Sorry about double post, as well as the delay. Wanted to double check some other things prior to responding.
Here is the code. I removed as much outside code to keep this brief and I also wanted to confirm that the outside code was not impacting anything.
Server:
import java.io.*;
import java.net.*;
public class GameMasterServer{
static final int HOSTPORT = 4321;
int cnt = 0;
public GameMasterServer()
{
OrderServer os = new OrderServer();
os.start();
}
public class OrderServer extends Thread{
ServerSocket providerSocket;
Socket connection = null;
BufferedReader inCommand;
BufferedWriter outCommand;
String message;
boolean masterServer;
public OrderServer()
{
masterServer = true;
}
public OrderServer(Socket s)
{
connection = s;
masterServer = false;
}
@Override
public void run()
{
try{
if (masterServer) {
providerSocket = new ServerSocket(HOSTPORT);
OrderServer ls;
while (true) {
ls = new OrderServer(providerSocket.accept());
ls.start();
}
}
else
{
String line;
inCommand = new BufferedReader(new InputStreamReader(connection.getInputStream()));
if((line = inCommand.readLine())!=null)
{
outCommand = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
outCommand.write(line.trim() + System.getProperty("line.separator"));
outCommand.flush();
outCommand.close();
System.out.println(line.trim() + " " + ++cnt);
}
}
}
catch (SocketException ex) {System.out.println("SOCKET EXCEPTION");}
catch (IOException ex) {System.out.println("IOEXCEPTION");}
finally {
try { if (providerSocket != null) providerSocket.close(); } catch (Exception ex) {System.out.println("SOCKET NULL ERROR");}
}
}
}
}
Client:
Thread updateThread = new Thread()
{
@Override
public void run() {
while(runThreads){
try {
sendMessage("Hello Doctor");
}
catch (SocketTimeoutException se) {System.out.println("SSDEBUG : DROPPED PACKET");}
catch (Exception e) {
System.out.println("SSDEBUG : COMM ERROR");
e.printStackTrace();
}
}
}
};
private String sendMessage(String msg) throws IOException {
BufferedWriter outCommand;
BufferedReader inCommand;
String response;
Socket hostConnection = new Socket();
System.out.println("1");
hostConnection.connect(new InetSocketAddress(StaticVariables.HOSTIP, StaticVariables.HOSTPORT),100);
outCommand = new BufferedWriter(new OutputStreamWriter(hostConnection.getOutputStream()));
inCommand = new BufferedReader(new InputStreamReader(hostConnection.getInputStream()));
outCommand.write(msg + System.getProperty("line.separator"));
System.out.println("2");
outCommand.flush();
messagesentcount++;
response = inCommand.readLine();
System.out.println("3");
outCommand.close();
inCommand.close();
hostConnection.close();
System.out.println("4");
return response;
}
The problem occurs on the hostConnection.connect. It will hang there (it doesn't now because I attempted a timeout, now it will just timeout constantly for a 15 second span.
To reiterate, the client is on Wi-fi and this problem does not occur whatsoever when using localhost.