• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Error connect client via socket

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 3572
505
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic