Results 1 to 8 of 8
  1. #1
    eLancaster is offline Member
    Join Date
    Jan 2011
    Posts
    93
    Rep Power
    0

    Default How do I find out what I.P address to give to a Socket?

    I've just started learning about Servers and Sockets.
    I made a client program which I run in one cmd window (on Windows 7)
    and I made a server program which I run on another cmd window.

    How do I find out what I.P address to give to my client program? I really don't know much about servers so please keep it simple. I do know how to use a command line.

  2. #2
    eLancaster is offline Member
    Join Date
    Jan 2011
    Posts
    93
    Rep Power
    0

    Default

    My server has a local host address of I.P is 0.0.0.0/0.0.0.0.
    I've given the client an I.P of 12.12.12.12
    The connection always times out.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    If both programs are on the same machine, then use the localhost address: 127.0.0.1
    The client would use the localhost address to connect to a server on the same machine.

  4. #4
    eLancaster is offline Member
    Join Date
    Jan 2011
    Posts
    93
    Rep Power
    0

    Default

    Totally worked. So for any PC in the whole entire world, the address of the computer you're working on is 127.0.0.1 (irrespective of Operating System)?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    I think that is supposed to be the standard, but I don't know for sure. I've only worked on Windows and Ubuntu. I think it also works on Macs

  6. #6
    eLancaster is offline Member
    Join Date
    Jan 2011
    Posts
    93
    Rep Power
    0

    Default

    I see. One more question : how can i access my server from my browser? Is that even possible?

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    Yes you can. I do it all the time with my test server. Enter a location of:
    http://127.0.0.1:<porthere>

    Where <porthere> is the port number the server is listening on. Default is 80. So if you're using the default:
    http://127.0.0.1

  8. #8
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default

    Quote Originally Posted by eLancaster View Post
    So for any PC in the whole entire world, the address of the computer you're working on is 127.0.0.1 (irrespective of Operating System)?
    The IPv4 loopback is 127/8 (127-dot-anything). The IPv6 loopback is ::1 (0:0:0:0:0:0:0:1). Your hosts file probably contains an entry for "localhost" that maps to one of these. So, for example, you could use the URL "http://localhost" (optionally with a port number) to connect to a HTTP server on your own computer.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Cannot find a free socket for the debugger
    By poojadgupta in forum Eclipse
    Replies: 0
    Last Post: 05-04-2011, 07:16 AM
  2. Replies: 1
    Last Post: 07-02-2010, 01:18 PM
  3. Give me some Assigment please
    By mindblaster in forum New To Java
    Replies: 2
    Last Post: 02-05-2010, 09:05 PM
  4. append response to the request from Socket and write to another socket
    By vaibhav_singh_vs@yahoo.co in forum Networking
    Replies: 3
    Last Post: 04-17-2009, 07:02 PM
  5. Please give me a solution
    By ivvgangadhar in forum AWT / Swing
    Replies: 5
    Last Post: 11-14-2008, 01:43 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
  •