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
How to use the PF_LOCAL and AF_LOCAL Macros?
HOW TCP/IP Handles Duplicated Packets?
How to open socket file in linux?
How to Bind a Specific Interface Address?
How to Test with No Server?
How to Examin the /etc/services File?
How TCP/IP Handles Lost Packets?
What is socket connection?
What are Anonymous Calls?
What are sockets used for?
How to Allocate IP Addresses?
how to get client port number in server socket programming??
How to Perform Endian Conversions?
How to Form Traditional Local Addresses?
How to Write a UDP Datagram Client?