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 Bind Addresses to a Socket?

1312


How to Test with Other IP Numbers?

1447


Can a socket have multiple connections?

766


How to Deal with Duplicated Sockets?

1468


What is the use of SOCK_STREAM Socket Type?

1328


How to Reply to a Wild Address?

1560


How to Write a UDP Datagram Server?

1257


What is the use of recvfrom(2) Function?

1431


What is socket abstraction?

784


What are sockets used for?

760


How to Write a UDP Datagram Client?

1301


How to Specify the Domain of a Socket?

1414


How do udp sockets work?

771


How to Understand Netmask Values?

1253


What are sockets in linux?

848