Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
163 views2 pages

Simple ARQ Code For Receiver in C

This document contains C code that implements a reliable data transfer between a client and server over UDP using go-back-N ARQ. The server code accepts incoming connections, reads frames of data sent from the client, and sends responses with status and sequence numbers back to the client. The code is designed to transfer 10 frames of data reliably between the client and server.

Uploaded by

Rakesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views2 pages

Simple ARQ Code For Receiver in C

This document contains C code that implements a reliable data transfer between a client and server over UDP using go-back-N ARQ. The server code accepts incoming connections, reads frames of data sent from the client, and sends responses with status and sequence numbers back to the client. The code is designed to transfer 10 frames of data reliably between the client and server.

Uploaded by

Rakesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// ARQ - client server

// Stop & Wait basics


// receive.c
// written at asmaitha wireless
// contact - [email protected]
/*server.c and client.c - implementation of go-back-n ARQ in C
by Elijah Jordan Montgomery <[email protected]>
Server.c implements a reliable data transfer over UDP in C
client.c implements a reliable data transfer client over UDP in C
Both of these programs use the go-back-n ARQ, that is lost data is
automatically resent. These programs are hardcoded to transfer
to compile:
gcc -o server server.c
gcc -o client client.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#define SUCCESS 1
#define FAILURE 0
#define NO_OF_FRAMES 10
typedef int BIT_32_VAR_INT ;
typedef char BIT_8_VAR_CHAR ;
void error ( BIT_8_VAR_CHAR *msg )
{
perror ( msg ) ;
exit ( 1 ) ;
}
typedef struct pdu_data
{
BIT_32_VAR_INT SN ;
BIT_8_VAR_CHAR data[80] ;
BIT_32_VAR_INT status ;
}PDU_DATA;
int main () {
PDU_DATA send_data[10] , recv_data[10] ;
BIT_32_VAR_INT socket_fd , newsocket_fd , port_no , client_len ;
// char buffer[256] ;
struct sockaddr_in serv_addr , cli_addr ;
int sizeof_read_data , counter_1 ;
//char buf[256] ;
socket_fd = socket ( AF_INET , SOCK_STREAM , 0 ) ;
if ( socket_fd < 0 )
{
error ( "error in socket opening " ) ;
}
bzero ( ( char * ) &serv_addr , sizeof ( serv_addr ) ) ;
port_no = atoi ( "7100" ) ;
serv_addr.sin_family = AF_INET ;
serv_addr.sin_addr.s_addr = INADDR_ANY ;
serv_addr.sin_port = htons ( 6000 ) ;
if ( bind ( socket_fd , ( struct sockaddr * ) &serv_addr , sizeof ( serv_a
ddr ) ) < 0 )
error ( "error in binding" ) ;
listen ( socket_fd , 5 ) ;
client_len = sizeof ( cli_addr ) ;
newsocket_fd = accept ( socket_fd , ( struct sockaddr * ) &cli_addr , &cli
ent_len ) ;
if ( newsocket_fd < 0 )
error ( "error in accept " ) ;
// bzero ( buffer , 256 ) ;
while ( 1 )
{
for ( counter_1 = 0 ; counter_1 < NO_OF_FRAMES ; counter_1++ )
{
sizeof_read_data = read ( newsocket_fd , &recv_data[counter_1] , siz
eof ( recv_data[counter_1]) ) ;
if ( sizeof_read_data < 0 )
error ( "error in reading from socket " ) ;
printf ( "client sended : %s with SN %d :\n" , recv_data[counter_1].
data , recv_data[counter_1].SN) ;
printf ( "enter a reply to client : " ) ;
scanf ( "%s",send_data[counter_1].data ) ;
printf ( "\nenter a SN for next you want to receive : " ) ;
scanf ( "%d",&send_data[counter_1].SN ) ;
if ( send_data[counter_1].SN <= recv_data[counter_1].SN )
counter_1 -= 1 ;
send_data[counter_1].status = SUCCESS ;
write ( newsocket_fd , &send_data[counter_1] , sizeof ( send_data[c
ounter_1]) ) ;
}
bzero ( &recv_data[counter_1].data , sizeof ( recv_data[counter_1].data )
) ;
read ( newsocket_fd , &recv_data[counter_1] , sizeof ( recv_data[counter_1
] ) ) ;
printf ( "it's end Thank YOu : \n" ) ;
exit ( 1 ) ;
}
return 0 ;
}

You might also like