> I'm currently working on a Chat Program, and i'm having problems
> with my sockets. Alltough I'm sure I use the right port and IP
> adress, the socket still can't connect. What could cause this
> problem? Could it be because of my router or because of proxy
> settings?
Many things could cause the problem. Start by posting the exact stack
trace you get when the connection fails.
Then try using a tool like telnet to connect to the same address and
port number and see what happens. If you get a similar error, you can
assume that this particular problem isn't caused by the client.
Normally if you get "Connection refused" it indicates that the server
isn't listening at the given address:port, or you aren't connecting
where you think you are.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Start with a ping to see if you can get to the remote machine...
=> ping remotemachine
If that works, do a netstat -a on the remote machine to see if the
socket is in a listening state..
=>netstat -a |grep 1234
> Hi,
> I'm currently working on a Chat Program, and i'm having problems with
> my sockets. Alltough I'm sure I use the right port and IP adress, the
> socket still can't connect.
> What could cause this problem?
> Could it be because of my router or because of proxy settings?
I always have problems with my socks too. Can't ever seem to find a
matching pair.
Could be your router, could be proxy settings, could be a firewall, could
be a dns problem, ... What is the exact error message? Does it work on
localhost? Is the server running (and listening) before the client tries
to connect? Some more information - and testing - would be helpful.

Signature
Beware the False Authority Syndrome
pieterblomme - 23 Dec 2005 20:01 GMT
/**
* Connects this Radio to another user or the main server. The
Radio stops listening
*
* @param host The address of the other user
* @return true if succes
*/
public boolean connect(String host)
{
//still have to find out how to add the none status with an or
statement
if(status == "none" | status == "listening")
{
try
{
//create an inner class for a thread that will run the
socket, since otherwise, the main thread will block
class SocketThread extends Thread
{
//instance variables
private Socket socket;
private int port;
private String host;
//constructor
public SocketThread(Socket socket, int port, String
host)
{
this.socket = socket;
this.port = port;
this.host = host;
}
//run method
public void run()
{
try
{
Socket socket = new Socket(host, port);
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
//create a socket for the connection
SocketThread socketThread = new SocketThread(socket,
port, host);
socketThread.start();
//Announce that you are connected
System.out.println("Connected");
//specifie the input and output streams
input = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
output = new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream()));
//change the status
status = "talking";
//return that the action was succesfull
return true;
}
//catch possible IOExceptions
catch(IOException e)
{
System.out.println(e.getMessage());
return false;
}
}
//if the Radio is busy, it cannot connect, so it returns false
else
{
return false;
}
}
That's the code of the connect method of my chat system
pieterblomme - 23 Dec 2005 20:02 GMT
/**
* Connects this Radio to another user or the main server. The
Radio stops listening
*
* @param host The address of the other user
* @return true if succes
*/
public boolean connect(String host)
{
//still have to find out how to add the none status with an or
statement
if(status == "none" | status == "listening")
{
try
{
//create an inner class for a thread that will run the
socket, since otherwise, the main thread will block
class SocketThread extends Thread
{
//instance variables
private Socket socket;
private int port;
private String host;
//constructor
public SocketThread(Socket socket, int port, String
host)
{
this.socket = socket;
this.port = port;
this.host = host;
}
//run method
public void run()
{
try
{
Socket socket = new Socket(host, port);
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
//create a socket for the connection
SocketThread socketThread = new SocketThread(socket,
port, host);
socketThread.start();
//Announce that you are connected
System.out.println("Connected");
//specifie the input and output streams
input = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
output = new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream()));
//change the status
status = "talking";
//return that the action was succesfull
return true;
}
//catch possible IOExceptions
catch(IOException e)
{
System.out.println(e.getMessage());
return false;
}
}
//if the Radio is busy, it cannot connect, so it returns false
else
{
return false;
}
}
That's the code of the connect method of my chat system
pieterblomme - 24 Dec 2005 06:54 GMT
I think the problem should be in my code, but it could allways be the
fault of my network too.
I'm testing the system on a local network with two linuxes and a
windows.
If I print e.getMessage(), I get Socket not connected because i try to
get the input- and outputstream of the socket, and a few minutes later
Connection timed out.
Alun Harford - 25 Dec 2005 09:38 GMT
>I think the problem should be in my code, but it could allways be the
> fault of my network too.
[quoted text clipped - 4 lines]
> get the input- and outputstream of the socket, and a few minutes later
> Connection timed out.
Post the server code and we might be able to help you (or at least the code
that handles listening for connections)
Alun Harford