how to get client port number in server socket programming??
Answer Posted / rps
@Maddy :-)
After the Accept Call in server Program..
ClientFD = accept(SockFD,(struct sockaddr *)&ClientAddr,(int*)&SinSize);
You will get Client IP and Port Number using this --
printf(" Server got a connection from Client (%s : %d)\n",
inet_ntoa(ClientAddr.sin_addr),ntohs(ClientAddr.sin_port));
| Is This Answer Correct ? | 3 Yes | 3 No |
Post New Answer View All Answers
How to Bind Addresses to a Socket?
How to Test with Other IP Numbers?
Can a socket have multiple connections?
How to Deal with Duplicated Sockets?
What is the use of SOCK_STREAM Socket Type?
How to Reply to a Wild Address?
How to Write a UDP Datagram Server?
What is the use of recvfrom(2) Function?
What is socket abstraction?
What are sockets used for?
How to Write a UDP Datagram Client?
How to Specify the Domain of a Socket?
How do udp sockets work?
How to Understand Netmask Values?
What are sockets in linux?