socket constructor with IP adress?

is thre a constructor for a socket that uses IP address . My serevr is runnig on my machine on IP address 127.0.0.1. How can I connect a client on this using the socket constructor?ie socket in = new Socket(-? , 8189);
[274 byte] By [sseans] at [2007-9-26 1:22:07]
# 1

This is right from the VisualAge API Reference:

java.net.*

public Socket(InetAddress address, int port) throws IOException

Creates a stream socket and connects it to the specified port number at the specified IP address.

public InetAddress()

This class represents an Internet Protocol (IP) address.

Applications should use the methods getLocalHost, getByName, or getAllByName to create a new InetAddress instance.

Hope that helps!

Xavier3742 at 2007-6-29 0:58:42 > top of Java-index,Core,Core APIs...
# 2

You can use the IP address as a string: socket in = new Socket("18.29.1.35", 8189);

Are you sure that you want to connect to 127.0.0.1 from the client? You see, that IP always refers to the current computer - on the client it's the client and on the server it's the server ... Not very useful for you, I think!

jsalonen at 2007-6-29 0:58:43 > top of Java-index,Core,Core APIs...
# 3
how else can I test my java server code and a client code ? I tried socket("127.0.0.1",8189) but I dont think it worked. no compile error of course but no runtime response either. maybe some other mistake?
sseans at 2007-6-29 0:58:43 > top of Java-index,Core,Core APIs...
# 4

Options:

Socket s = new Socket("127.0.0.1", 8189) ;

Socket s = new Socket("localhost", 8189) ;

Here it is assumed that the server you are running is on the same host (PC or computer) on which you are trying to run the client.

Look at the java.net.Socket javadoc for complete info.

Hope this helps !!!

TVSM at 2007-6-29 0:58:43 > top of Java-index,Core,Core APIs...