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 Form Internet (IPv4) Socket Addresses?
How socket is created?
What is the use of recvfrom(2) Function?
HOW TCP/IP Handles Duplicated Packets?
What is the use of PF_LOCAL and SOCK_STREAM?
How to Test with Other IP Numbers?
What are Anonymous Calls?
How to Choose a Socket Type?
How to Generate Addresses?
What are Nameless Sockets?
How to Initialize a Wild Internet Address?
How to Write a UDP Datagram Client?
Can a socket have multiple connections?
What is the use of PF_INET and SOCK_DGRAM?
What is the difference between socket & port?