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 is socket linux?

478


What is the use of setprotoent(3) Function?

1143


Why socket programming is used?

486


How to Define a Socket?

1000


How to Specify an X.25 Address?

1001






What are Reserved IP Numbers?

995


Why bind system call is required in socket programming?

448


How to Generate Addresses?

975


What is the use of inet_network()?

993


How to Initialize a Wild Internet Address?

1037


What are Anonymous Calls?

993


how to get client port number in server socket programming??

1965


How to Bind a Specific Interface Address?

990


How to Test with Other IP Numbers?

1074


How to Close Sockets?

1031