Results 1 to 7 of 7

Thread: Sockets

  1. #1
    Maya is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default Sockets

    Hii,

    I am doing a client server program, The program works on the same computer (localhost), but if I give the name of another computer "MAYA-PC" I am getting the following error

    java.net.UnknownHostException: MAYA-PC
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at type1.<init>(type1.java:65)
    at type1.keys(type1.java:271)
    at type1.access$0(type1.java:264)
    at type1$1.run(type1.java:51)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    why is this happening. Both the computers are connected to the same network

    Please Help me.

    Regards,
    Maya

  2. #2
    Maya is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    But on my computer MAYA-PC, which have both client and server program, even if I give socket = new Socket("MAYA-PC", 7777);....I am getting output. I thought that it may be a network problem and tried working client and server programs on different computers on another network too. But I got the same error.

  3. #3
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    You can't connect connect through sockets using a computer name :eek:
    You need to use the computer's IP Address.

  4. #4
    Maya is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    But I read a tutorial Sockets programming in Java: A tutorial - JavaWorld
    which have


    " If you are programming a client, then you would open a socket like this:

    Socket MyClient;
    MyClient = new Socket("Machine name", PortNumber);


    Where Machine name is the machine you are trying to open a connection to, and PortNumber is the port (a number) on which the server you are trying to connect to is running. When selecting a port number, you should note that port numbers between 0 and 1,023 are reserved for privileged users"

  5. #5
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    In order to connect by name, you either have to have a host table that maps host names to IPs or you have to have a DNS server running that maps names to IPs.

  6. #6
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Instead of having a host table or hosting a DNS server, just assign static IP addresses inside your network and connect by IP.

  7. #7
    Maya is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

Similar Threads

  1. Sockets
    By PhQ in forum New To Java
    Replies: 1
    Last Post: 05-04-2010, 04:36 AM
  2. Problem (sockets)
    By Blacknight962 in forum New To Java
    Replies: 3
    Last Post: 08-16-2009, 01:56 AM
  3. Sockets NIO
    By aamp in forum New To Java
    Replies: 3
    Last Post: 01-15-2009, 11:56 AM
  4. Sockets
    By Zosden in forum Networking
    Replies: 16
    Last Post: 05-27-2008, 05:55 PM
  5. Help with Sockets
    By Eric in forum Networking
    Replies: 3
    Last Post: 12-01-2007, 09:09 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
  •