DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2007
    Posts
    2

    Angry Problem with Socket :: java.net.ConnectException

    Hi,
    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("172.26.94.199");
    ServerSocket serSoc = new ServerSocket(8000,50, IPServer);
    while(true) {
    soc = serSoc.accept();
    start();
    }
    For Client
    InetAddress serverIP = InetAddress.getByName("172.26.94.199");
    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();
    start();
    }
    For Client :
    soc = new Socket("localhost", 8000);


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

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

  3. #3
    Join Date
    Jan 2007
    Posts
    2
    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
    Posts
    2
    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

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links