The document describes a server-side algorithm to initialize a server socket, listen for connections, accept an incoming connection, receive and process frames from a client, and close the connection. It also describes a client-side algorithm to initialize a client socket, establish a connection with the server, send and receive data in a loop, and close the connection.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
9 views2 pages
7stop&wait (SWS, SWC)
The document describes a server-side algorithm to initialize a server socket, listen for connections, accept an incoming connection, receive and process frames from a client, and close the connection. It also describes a client-side algorithm to initialize a client socket, establish a connection with the server, send and receive data in a loop, and close the connection.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
-----Server Side Algorithm-----
Step 1: Initialize Server
Create a socket using socket() function
Set server address family to AF_INET Set server port number to 5600 Set server IP address to 127.0.0.1 Bind the socket to the server address using bind() function
Step 2: Listen for Connections
Listen for incoming connections using listen() function with a backlog of 5
If successful, print "Listening"
Step 3: Accept Connection
Accept an incoming connection using accept() function
If successful, store the new socket descriptor in newSock
Step 4: Receive and Process Frames
-Initialize a counter k to 5 and m to 1
-Loop until k becomes 0 --Receive a frame from the client using recv() function --If successful, check if the received frame starts with "frame" ---If yes, print "Received frame <m> successfully" ---If no, print "Frame <m> not received" --If m is even, send an "ack" response --If m is odd, simulate an ACK loss by sending "kca" and then retransmitting "ack" after a delay --Send the response back to the client using send() function --Decrement k and increment m
Step 5: Close Connection
Close the new socket descriptor using close() function
-----Client-Server Communication Algorithm-----
Step 1: Initialize
Create a socket for the client using socket() function.
Set up the server address using struct sockaddr_in and specify the IP address and port number.
Step 2: Establish Connection
Use connect() function to establish a connection with the server.
Check if the connection is successful. If not, print an error message and exit.
Step 3: Send and Receive Data
-Initialize a counter k to 5 and m to 1.
-Loop until k becomes 0: --Check if m is less than or equal to 5. If true, print a message indicating the packet being sent. --If m is even, set the buffer to "frame". Otherwise, set the buffer to "error" and simulate packet loss by waiting for 3 --Send the buffer data to the server using send() function. --Check if the send operation is successful. If not, print an error message and exit. --Receive data from the server using recv() function. --Check if the receive operation is successful. If not, print an error message and exit. --Check if the received data is an acknowledgement ("ack"). If true, print a message indicating the acknowledgement . --Decrement k and increment m.