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 are the Advantages of TCP/IP?
How to use the PF_LOCAL and AF_LOCAL Macros?
How TCP/IP Handles Sequencing?
What are sockets used for?
What is the use getservent(3)?
Can you send and receive on the same socket at the same time?
What are Private IP Numbers?
What is the use of SOCK_STREAM Socket Type?
How to Close Sockets?
What is the use of PF_INET and SOCK_DGRAM?
What is the use of PF_LOCAL and SOCK_STREAM?
How to test socket connection in linux?
How to Form Abstract Local Addresses?
What is the use of endprotoent(3) Function
What is socket abstraction?