LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   tcp client socket : how to get own port number ?? (https://www.linuxquestions.org/questions/programming-9/tcp-client-socket-how-to-get-own-port-number-835686/)

vlyamtse 10-01-2010 02:42 PM

tcp client socket : how to get own port number ??
 
Hi,
I am working with simple tcp client to establish connection to sockaddr_in servAddress and send data segment:
...
connect(sockfd,&servAddr,sizeof(servAddr)) < 0)
send(sockfd, pkt, pktLen, 0);
close(sockfd);
...
Elementary... Here's the tricky part: next i have to handle user level ack the server is sending to "client"... To do that i have to open server socket on the same port number the system assigned to my client socket before. How can i get it ( in user level code)?
Thanks,
-V

kbp 10-01-2010 05:26 PM

Code:

connect(sockfd,&servAddr,sizeof(servAddr)) < 0)
send(sockfd, pkt, pktLen, 0);
recv(...);
close(sockfd);

..from memory

theNbomr 10-01-2010 07:26 PM

I sounds like you are asking how to do bi-directional communcations on a socket. The answer is too simple: each end of the connection is a read/write file descriptor. Simply leave the socket open until all of the communication has transpired in each direction.

--- rod.


All times are GMT -5. The time now is 06:03 AM.