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


Please Help Members By Posting Answers For Below Questions

What does socket consist of?

605


Are sockets full duplex?

615


How to Specify an X.25 Address?

1213


How TCP/IP Handles Sequencing?

1288


What is the use of SOCK_DGRAM Socket Type?

1166


What is the use of PF_INET and SOCK_DGRAM?

1201


What are Reserved IP Numbers?

1161


Can you send and receive on the same socket at the same time?

601


How to read socket file in linux?

691


How to perform I/O on Sockets?

1085


What is socket linux?

618


How to Bind Addresses to a Socket?

1119


How to Form Abstract Local Addresses?

1139


How socket is created?

596


How does socket communication work?

655