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 inet_network()?
How to Initialize a Wild Internet Address?
How to Test the Datagram Client and Server?
HOW TCP/IP Handles Duplicated Packets?
How to Write a UDP Datagram Server?
Why socket programming is used?
How to use the socket(2) Function?
What is socket linux?
How does socket communication work?
How to Reply to a Wild Address?
How to Form Local Addresses?
How to Examin the Generic Socket Address?
What are sockets in linux?
What is the difference between socket and port?
How to Generate Addresses?