This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error recognizing IP and Port from Client using getInetAddress getHostAddress and .getLocalPort  RSS feed

 
Fernando Skackauskas
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I have a program that receives via socket a data packet. My program is the Server

I need to give back to the Client that has been received or not.

But when I try to identify the IP and Client port, it returns "0.0.0.0.0" and the port is the same port from my Server.

I am using the following commands:



At this point, the remoteIP = "0.0.0.0" and the same RemotePort = Server (2712).

Where is the mistake? wHY it does not recognize the IP and client port by getInetAddress and getLocalPort command?

Thank you,

Fernando
 
Ron McLeod
Saloon Keeper
Posts: 1562
222
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be working with the socket returned by the accept() rather than the server's listening socket. For example the port of the remote socket would be returned by s.getPort().

Also - this post belongs in the Sockets and Internet Protocols forum, the Ranch Office forum is for issues related to the site itself.
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now somebody has suggested which forum this discussion belongs in (thank you), I can move it!
No, somebody has beaten me to it and it has already been moved.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fernando,

Please choose the forum carefully before posting a question.

I've moved your post to Sockets forum.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell, I won this round!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!