how to get client port number in server socket programming??
Answer Posted / nainesh
After accepting connection on socket of server side. we can
get the client ip address and port by to functions. These
functions are belonging in "/usr/include/arpa/inet.h" header
file.
Here is some scratch from the code.
socket2 = accept(socket1, (struct sockaddr *)&client, &addrlen);
printf("%s\n",inet_ntoa(client.sin_addr));
printf("%d\n",(int) ntohs(client.sin_port));
| Is This Answer Correct ? | 14 Yes | 3 No |
Post New Answer View All Answers
What is the use of recvfrom(2) Function?
How to perform I/O on Sockets?
Can a socket have multiple connections?
How to Define a Socket?
How to Examin the Generic Socket Address?
How to Test the Datagram Client and Server?
What is socket linux?
What are sockets in linux?
What is socket and how it works?
How to Understand Netmask Values?
How to Examin the /etc/services File?
How to Generate Addresses?
How TCP/IP Handles Sequencing?
How TCP/IP Handles Flow Control?
What are Private IP Numbers?