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 / 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

How to Form Internet (IPv4) Socket Addresses?

1487


How socket is created?

763


What is the use of recvfrom(2) Function?

1506


HOW TCP/IP Handles Duplicated Packets?

1605


What is the use of PF_LOCAL and SOCK_STREAM?

1569


How to Test with Other IP Numbers?

1494


What are Anonymous Calls?

1341


How to Choose a Socket Type?

1284


How to Generate Addresses?

1311


What are Nameless Sockets?

1538


How to Initialize a Wild Internet Address?

1647


How to Write a UDP Datagram Client?

1378


Can a socket have multiple connections?

819


What is the use of PF_INET and SOCK_DGRAM?

1396


What is the difference between socket & port?

890