LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2011, 01:31 AM   #1
pawan_linux
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Rep: Reputation: 0
port number not matching


Hi,
In TCP client server,if I explicitly bind client port for connecting with server at Client side it is showing correct port.However on server when I accept connection from client the port number of client is not matching.

Client is running on windows and I am using htos(portnum) before binding.

Server is running on Linux and ntohs() is used before displaying port.

on both sides netstat is showing different port numbers.

Please give the solution if u understand the problem

Thanks
for reading...
 
Old 03-29-2011, 05:36 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Moved: This thread is more suitable in Programming and has been moved accordingly to help your question get the exposure it deserves.
 
Old 03-29-2011, 05:53 AM   #3
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
When you indicated that you are binding the client's socket to a port, do you mean that you are connecting to the server? It is not typical for the client to bind() to a port, but I suppose it could be done. Either way the client will still need to connect() to the server.

When I tested, my client has an ephemeral port assigned to it, and it is connected to the server. I can verify this using netstat -atp.

On the server side (different machine), I can again verify the connection using netstat. The output is the converse of what is shown on the client side.

For example, on the client side:
Code:
tcp        0      0 clienthost:59985       serverhost:9000            ESTABLISHED 29610/client
On the server side:
Code:
tcp        0      0 serverhost:9000            clienthost:59985       ESTABLISHED 7328/server

P.S. I just retested, having my client bind() specifically to a port number that I chose at random. Sure enough, netstat reports, on both the client-side and server-side, that my client is using said port. If your client is using bind(), make sure that 1) you are using an unused port number, and 2) you verify that bind() succeeded.

Last edited by dwhitney67; 03-29-2011 at 05:59 AM.
 
Old 03-29-2011, 01:16 PM   #4
pawan_linux
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Original Poster
Rep: Reputation: 0
yes bind is verified success, but i m not getting the converse on server and client as shown above...

thanks
 
Old 03-30-2011, 02:42 AM   #5
TimothyEBaldwin
Member
 
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
Is there a NAT between the client and server?
 
Old 03-31-2011, 12:49 AM   #6
pawan_linux
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Original Poster
Rep: Reputation: 0
client,server are on different networks and I guess NAT is being used in between.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Make x number of changes matching pattern with sed grail Programming 7 08-08-2010 06:58 AM
Perl Script needed to be reversed to output matching, not non-matching 0bfuscated Programming 2 07-20-2010 10:51 AM
LXer: Streamlined Perl Number Matching Script For Unix Or Linux LXer Syndicated Linux News 0 09-18-2008 12:00 PM
USB to serail port adaptor COM port number areftaidi Linux - Software 2 09-25-2007 01:05 AM
Algorithm design: number matching PB0711 Programming 8 03-26-2007 02:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration