Transferring Files Over RS232 C Program

Algorithm Steps:


1. Start.
2. Open the file recvfile.txt in write mode.
3. Receive the port number and establish socket connection.
4. Listen to client’s request using system call listen() .
5. While the message size is not zero, receive the client message and write it in to a file.
6. Close the socket connection,
7. Stop.

1. Start.
2. Pass server address and file name as command line arguments.
3. Open the file and establish connection using socket().
4. Using memset(), get the size of client address.
5. Connect to server using connect()system call.
6. While not end of file, print the contents into the file.
7. Close the socket connection.
8. Stop.

1. socket()
socket(protocol family, type of socket, protocol);

2. connect()
connect(client socketid, client address, length of server address);

3. send()
send(int s, void $buf, size_tlen, int flags);

4. recv()
recv(int s, void $buf, size_tlen, int flags);

5. listen()
listen(server socket, protocol type for number of connection) ;

6. accept()
accept(socket id, client information, client size);

//RS232 Server Program:
#define MAX 5
#define BUF 256
int main(int argc, char **argv)
    int sersock, clisock, portno;
    struct sockaddr_in echoseraddr,echocliaddr;
    char echobuffer[BUF];
    unsigned int clilen, recvmsgsize;
    FILE *fp=fopen(“recvfile.txt”,”w”);
    bind(sersock,(struct sockaddr*)&echoseraddr,sizeof(echoseraddr));
    printf(“\nServer waiting for client on port %d”, portno);
    clisock=accept(sersock,(struct sockaddr *)&echocliaddr, &clilen);
    printf(“\nFile received and socket closed”);
    return 0;
//RS232 Client Program:
#define BUF 256
int main(int argc, char **argv)
    int sock, portno;
    struct sockaddr_in echoseraddr;
    char *serIP, *filename, echobuffer[32];
    FILE *fp;
    connect(sock,(struct sockaddr *)&echoseraddr, sizeof(echoseraddr));
    printf(“\nThe %s send over RS232”,filename);
    return 0;

In Server Side:
cc rsser.c
./a.out 8222
Server waiting for client on port 8222
File received and socket closed
cat recvfile.txt
this is rs232 program

In Client Side:
cc rscli.c
./a.out rsinput.txt 8222
The rsinput.txt send over RS232
cat > rsinput.txt
this is rs232 program

Post a Comment