• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why a different port number is shown

 
Abhishek KumarSoni
Ranch Hand
Posts: 61
Chrome Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends.......i was trying socket programming code in which i found unexpected behaviour as follow:
This was my server code

And this is client code


I execute server code and after that client code
output printed was -> my port is 52340 .
Why this unexpected behaviour??It should be -> my port is 4001?
 
Chan Ag
Rancher
Posts: 1089
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishek KumarSoni wrote:
This was my server code


...........
I execute server code and after that client code
output printed was -> my port is 52340 .
Why this unexpected behaviour??It should be -> my port is 4001?


Hint : Which socket is the variable sock pointing to? Is the port number of that socket 4001?

As an aside, you might want to consider renaming your class 'client' to 'Client' and class 'server' to 'Server'. I guess you already know why.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!