Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Cannot Open Socket on Specific Address/Port

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cannot Open Socket on Specific Address/Port

    Hello:

    I have to write an interface which is IP and port limited from the source for security reasons. I'm having a problem opening a socket using local values.

    new Socket(sHostAddr, nHostPort, InetAddress.getByName("127.0.0.1"), 1030);


    causes

    java.net.SocketException: Network is unreachable
    at java.net.PlainSocketImpl.socketConnect(PlainSocket Impl.java:-2)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:432)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.connect(Socket.java:478)
    at java.net.Socket.<init>(Socket.java:375)
    at java.net.Socket.<init>(Socket.java:249)
    at ts.sswitch.s.fcic.FCICConn.openSocket(FCICConn.jav a:569)
    at ts.portal.SingletonConn.transmitterLoop(SingletonC onn.java:202)
    at ts.sswitch.s.fcic.FCICConn$1.run(FCICConn.java:155 )
    at java.lang.Thread.run(Thread.java:680)


    Changing the local values

    new Socket(sHostAddr, nHostPort, InetAddress.getByName("localhost"), 12000);


    doesn't help. But removing the local values does.

    new Socket(sHostAddr, nHostPort);


    Unfortunately, I'm going to need these values. I had this working years ago on Java 5 on the PC. I'm trying now with Java 6 on Mac OS X 10.6.8. Thanks in advance for any help.

    Dan


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Location
    Home-Ujjain /Job-Mumbai
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cannot Open Socket on Specific Address/Port

    Hi,
    Contact me at sunil1raghu@gmail.com I will provide you a socket connection ebook for java. I hope that will clear your all socket related concepts
    Programmer

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Cannot Open Socket on Specific Address/Port

    One thing you can try is to use the NetworkInterface class to get the proper InetAddress.

Similar Threads

  1. Creating a serverSocket while sonnecting to a socket on the same port
    By vortexnl in forum Java Theory & Questions
    Replies: 0
    Last Post: February 14th, 2011, 01:33 PM
  2. Address Book Help
    By clevel211 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 21st, 2010, 09:42 PM
  3. Relay data from remote port to local port
    By chegers in forum Java Networking
    Replies: 0
    Last Post: November 7th, 2010, 12:46 PM
  4. Multiple socket on same port
    By Sanjith in forum Java Networking
    Replies: 2
    Last Post: October 22nd, 2010, 02:33 PM
  5. Port issue?
    By Brt93yoda in forum Java Theory & Questions
    Replies: 3
    Last Post: October 13th, 2010, 04:28 PM

Tags for this Thread