How to create Socket Programming Socket Creation Network Lab Program

To create a new socket by using the socket function.
Source code programming algorithm in c c++
STEP 1: Start the program.
STEP 2: Declare the socket header file sys/socket.h.
STEP 3: Declare fd1 and fd2 to store the field descriptor value.
STEP 4: Define the function, protocol and family for the socket to be created.
STEP 5: If fd value is positive then the fd value is returned.
STEP 6: If the fd value is negative then the error statement is displayed.
STEP 7: Stop the program.Socket Programming	Socket Creation Network Lab Program
Source Code Socket Program Socket Creation
#include<stdio.h>
#include<sys/socket.h>
int main( )
{
int fd1,fd2;
fd1=socket(PL_LOCAL,SOCK_DGRAM,0);
if(fd1==-1)
printf(“TCP Socket Creation Error\n”);
else
{
printf(“TCP Socket Creation”);
printf(“TCP Socket Field Description Value is
%d\n”,fd1);
}
fd2=socket(AF_INET,SOCK_STREAM,0);
if(fd2==-1)
{
printf(“TCP Socket creation Error\n”);
}
else
{
printf(“TCP Socket Creation”);
printf(“TCP Socket Field Descriptor Value is %d\n”,fd2);
}
return 0;
}
OUTPUT:

TCP Socket Creation

TCP Socket Field Descriptor Value is 3

TCP Socket creation Error.

RESULT:

Thus the program for creating a new socket is created and verified.

Post a Comment

0 Comments