Socket Binding Source code in C Programming Network CS1305


To create and bind a socket by using the socket function. The socket bind function is used in the chat application programming.
Algorithm Free Source code in C C++ Programming
STEP 1: Start the program.
STEP 2: Declare the variables fd, b and the port number.
STEP 3: Declare the family, type and protocol for the socket function.
STEP 4: Using the object initialize the port, address and family.
STEP 5: If fd value is positive then the socket is created else not created.
STEP 6: Use the bind function.
STEP 7: If the bind value is negative then binding error occurs.
STEP 8: otherwise the port number is printed.
STEP 9: Stop the program.

PROGRAM CS1305 Network Lab Socket Binding
#define PORT 2000
int main( )
int fd,b;
struct sockaddr_in myaddr;
printf(“Socket Creation Error”);
printf(“Socket is Created”);
printf(“Socket Field Descriptor Value is : %d”,fd);
b=bind(fd,(struct sockaddr*)&myaddr,sizeof(struct sockaddr));
printf(“Socket binding error”);
printf(“Socket is binded at port %d”,PORT);
return 0;
Output CS1305 Network Lab Socket Binding
Socket is Created
Socket Field Descriptor Value is 3
Socket is binded at port 2000
RESULT : Thus the program for binding the socket has
been created and verified in C source code Network lab CS1305.

No comments:
Write comments