I hope you can help. I am new to programming and I play with Java sockets.
The problem is the code below. for some reason commSocket = new Socket(hostName, portNumber);returns true, even if it is not connected to the server (the server has not yet been implemented!). Any ideas on this situation?
For hostName Im, pass my local computer IP address and port that is manually selected.
public void networkConnect(String hostName, int portNumber){
try {
networkConnected = false;
netMessage = "Attempting Connection";
NetworkMessage networkMessage = new NetworkMessage(networkConnected, netMessage);
commSocket = new Socket(hostName, portNumber);
System.out.println(commSocket.isConnected());
networkConnected = true;
netMessage = "Connected: ";
System.out.println("hellooo");
} catch (UnknownHostException e){
System.out.println(e.getMessage());
} catch (IOException e){
System.out.println(e.getMessage());
}
}
Many thanks.
EDIT: new Socket (.., ..); blocks, right? I thought that in this case, if it was handled without exception, then do we have a true join?
EDIT: I played with antivirus and now it works!
iTEgg source
share