Socket Accept Source in C programming Network lab


To verify the socket accept function by using other socket functions. It is used in the chat application program for connection oriented.
Free Source code Algorithm in C programming Socket Accept.
STEP 1: Start the program.
STEP 2: Declare the variables port number and queue length.
STEP 3: Using the object declare the family , address and port.
STEP 4: The socket is binded at a particular port.
STEP 5: The port number is displayed.
STEP 6: If the socket is in the listener mode then the accept
function is executed.
STEP 7: The server is to be waiting to connect the client.
STEP 8: Stop the program.

Free Source code Program CS1305 Network Lab

#define PORT 2000
#define quelen 5
int main( )
int fd;
struct sockaddr_in server,client;
printf(“Socket Creation Error\n”);
printf(“Socket Creation\n”);
printf(“Socket created descriptor value is %d\n”,fd);
if(bind(fd,(struct sockaddr*)&server,sizeof(struct sockaddr_in))!=-1)
printf(“Socket is binded at port %d”,PORT);
printf(“Socket Binding Error”);
printf(“Listen Error”);
printf(“Server is in Listener Mode”);
printf(“Server is waiting to connect to the client”);
if(accept(fd,struct sockaddr*)&client,sizeof(struct sockaddr_in*))=-1)
printf(“Accept Error”);
printf(“Server is in Accept Mode”);
printf(“Connection mode in with client %s”,inet_ntoa(client.sin_addr));
Output CS1305 Network Lab Socket Accept
Socket Created
Socket Field Descriptor Value is 3
Socket is binded at port 2000
Server is in Listener mode
Server is waiting to connect to the client.
RESULT : Thus the program for performing socket accept has
been created and verified. It will be used in the chat application connection oriented programming.

No comments:
Write comments