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.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Is it possible to call constructor and destructor explicitly?
- Assigning an integer to float and comparison in C/C++
- Assigning multiple characters in an int in C language
- How to bind to port number less than 1024 with non root access?
- Difference between IP address and Port Number
- Port Security in Computer Network
- Type-C Port in Computer Network
- Port Address Translation (PAT) on Adaptive Security Appliance (ASA)
- Difference Between Network Address Translation (NAT) and Port Address Translation (PAT)
- SSH Port Forwarding
- Port Address Translation (PAT) mapping to Private IPs
- Switch Port Analyzer (SPAN)
- TCP Server-Client implementation in C
- Reverse a string in C/C++ using Client Server model
- UDP Server-Client implementation in C
- Java Implementation of Deffi-Hellman Algorithm between Client and Server
- Difference between Client-Server and Peer-to-Peer Network
- TCP Client-Server Program to Check if a Given String is Palindrome
- Two way communication between Client and Server using Win32 Threads
- Distributed Objects Computing: The next generation of client-server computing