Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is the use of inet_network()?

1384


How to Initialize a Wild Internet Address?

1591


How to Test the Datagram Client and Server?

1386


HOW TCP/IP Handles Duplicated Packets?

1574


How to Write a UDP Datagram Server?

1269


Why socket programming is used?

838


How to use the socket(2) Function?

1452


What is socket linux?

792


How does socket communication work?

830


How to Reply to a Wild Address?

1573


How to Form Local Addresses?

1372


How to Examin the Generic Socket Address?

1354


What are sockets in linux?

863


What is the difference between socket and port?

883


How to Generate Addresses?

1291