• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error connect client via socket

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

I have a program that receives a data package via socket from a client.

The program detects the IP and client port to send to client a mensage confirmation.

But, when the program send the message back into its socket, it receives the following error message:

    Exception in thread "main" java.net.ConnectException: Connection timed out: connect
        at java.net.DualStackPlainSocketImpl.connect0 (Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect (DualStackPlainSocketImpl.java:79)
        at java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:339)



The code is as follows:



When try the command     occurs the error message.

NOTE: The server has no enabled Firewall.

What could be going wrong?

Thank you,

Fernando
 
Ron McLeod
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two issues. First, to get the port for the client you should be calling getPort() - see Error recognizing IP and Port from Client ... . Second, to reply to the client, write to the output stream for the same socket you read from - s.getOutputStream() - don't try and open a new socket connection back to the client (unlikely the client is listening for connections anyway).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!