Prerequisite: Socket programming in C/C++.
In socket programming, when server and client are connected then client is provided any random port number by operating system to run and generally, we don’t care about it, But in some cases, there may be a firewall on the client side that only allows outgoing connections on certain port numbers. So, it is highly probable that the port number provided to client by operating system may have been blocked by client firewall. In that case, we need to explicitly or forcefully assign any port number to the client on which it can operate.
Some protocol like NFS protocol requires client program to run on only certain port number and so in this case, client need to forcefully assigned that port number only as it runs on port number either on 111 or on 2049. This can be done using bind() system call with specifying particular port number in client side socket.
Below is the implementation Server and Client program where client will be forcefully get assigned a port number.
Server Side Program
Server Created Binded Correctly Listening ... Connection Established connection established with IP : 10.32.40.213 and PORT : 12010 Client : Hello
Client Side Program
Client Created Binded Correctly Client Connected Server : Hello
This article is contributed by Aditya Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- How to bind to port number less than 1024 with non root access?
- Is it possible to call constructor and destructor explicitly?
- Type-C Port in Computer Network
- Computer Network | Port security
- Assigning an integer to float and comparison in C/C++
- Assigning multiple characters in an int in C language
- UDP Server-Client implementation in C
- TCP Server-Client implementation in C
- Reverse a string in C/C++ using Client Server model
- Socket Programming in Java
- Socket Programming in Python
- Sort an array using socket programming in C
- Java Implementation of Deffi-Hellman Algorithm between Client and Server
- Socket Programming with Multi-threading in Python
- Socket Programming in C/C++: Handling multiple clients on server without multi threading