DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Jan 2007

    Angry Problem with Socket :: java.net.ConnectException

    I am new to socket programming but have experience in Java.
    My desktop is connected to the institute LAN and that is how I connect to the rest of the planet.
    Now I was trying to make a file tranfer protocol. The socket part of the code is :
    For Server:
    InetAddress IPServer = InetAddress.getByName("");
    ServerSocket serSoc = new ServerSocket(8000,50, IPServer);
    while(true) {
    soc = serSoc.accept();
    For Client
    InetAddress serverIP = InetAddress.getByName("");
    soc = new Socket(serverIP, 8000);

    When I run the client i get the Exception :
    java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
    at java.net.Socket.connect(Socket.java:507)

    The code was working brilliantly till I was using 'localhost', ie :
    For Server :
    ServerSocket serSoc = new ServerSocket(8000);
    while(true) {
    soc = serSoc.accept();
    For Client :
    soc = new Socket("localhost", 8000);

    Please help me. I just can't figure out the problem.

  2. #2
    Join Date
    Jan 2007
    Try something like these
    InetAddress serverIP = InetAddress.getByName("localhost");
    InetAddress serverIP = InetAddress.getByIP("");

  3. #3
    Join Date
    Jan 2007
    The code works well by using 'localhost' (both in server and client) but I want my application to work on a remote computer also. The program gives exceptions when I use the IP address of my machine. And I checked the method InetAddress.getByIP(".....") ; .It does not exist

  4. #4
    Join Date
    Jan 2007
    Try by changing the port number to 8002 or something like that....see if it works..sometimes port may be a problem.

Similar Threads

  1. CMR problem
    By vikassheelgupta in forum Java
    Replies: 0
    Last Post: 07-22-2005, 05:35 AM
  2. socket exception problem
    By sanu in forum Java
    Replies: 0
    Last Post: 03-18-2005, 08:57 AM
  3. Java Applet Compiler problem?
    By mdl in forum Java
    Replies: 3
    Last Post: 03-07-2005, 02:34 AM
  4. A non-blocking socket problem
    By mark a in forum .NET
    Replies: 0
    Last Post: 06-12-2002, 08:21 PM
  5. Replies: 0
    Last Post: 12-13-2001, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.