Develop an application For transferring Files over RS232 in Client side programming

Step by step algorithm: client RS232
Include the header file
Pass the IP address input file port number as argument to main function
Convert Port number to integer value
Open the file in read mode
Create a Socket using socket()
Fill the memory with constant byte using memset()
Define the port family
Connect the client to the socket
Get the contents from input file and sent it to server over the socket using send()
Close the socket
Stop the Cline program in RS232



CLIENT RS232 Source code in C language programming
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
#define BUF 256
int main(int argc,char **argv)
{
int sock;
struct sockaddr_in echoServAddr;
char *servIP,*filename,echoBuffer[32];
int bytesRcvd,portno;
FILE *fp;
servIP=argv[1];
filename=argv[2];
portno=atoi(argv[3]);
fp=fopen(filename,"r");
sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
memset(&echoServAddr,0,sizeof(&echoServAddr));
echoServAddr.sin_family=AF_INET;
echoServAddr.sin_addr.s_addr=inet_addr(servIP);
echoServAddr.sin_port=htons(portno);
connect(sock,(struct sockaddr*)&echoServAddr,sizeof(echoServAddr));
while(!feof(fp))
{
fgets(echoBuffer,BUF,fp);
send(sock,echoBuffer,strlen(echoBuffer),0);
}
printf("the %s send over rs232 \n",filename);
close(sock);
return 0; }

Output CS1305- NETWORK LAB
[it28@localhost studentwebsite]$Source.txt
Hai my studentwebsite visitor

[it28@localhost studentwebsite]$cat source.txt
Hai my studentwebsite visitor
[it28@localhost studentwebsite]$cc rsclient.c

[it28@localhost studentwebsite]$./a.out 192.168.1.111 source.txt 8000
The source.txt sent ouver RS232

Result
Thus the file over transferred over RS232 in Client side successfully.

Related post