I'm having trouble with my server code. Everytime I compile and execute the application hangs then crashes (not responds). I'm using the Slick2d game library which is single threaded. Here is my code-
package chill.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.*;
public class ChillServer {
int port;
String name = "[ChillServer]";
String fromclient;
String toclient;
public ChillServer(int portNumber) throws IOException
{
this.port = portNumber;
ServerSocket Server = new ServerSocket (port);
out("ChillServer established on port "+port);
while(true)
{
out("Listening for connections...");
Socket connected = Server.accept();
System.out.println( " THE CLIENT"+" "+
connected.getInetAddress() +":"+connected.getPort()+" IS CONNECTED ");
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader (connected.getInputStream()));
PrintWriter outToClient =
new PrintWriter(
connected.getOutputStream(),true);
while ( true )
{
System.out.println("SEND(Type Q or q to Quit):");
toclient = inFromUser.readLine();
if ( toclient.equals ("q") || toclient.equals("Q") )
{
outToClient.println(toclient);
connected.close();
break;
}
else
{
outToClient.println(toclient);
}
fromclient = inFromClient.readLine();
if ( fromclient.equals("q") || fromclient.equals("Q") )
{
connected.close();
break;
}
else
{
System.out.println( "RECIEVED:" + fromclient );
}
}
}
}
public void out(String s)
{
System.out.println(name+" "+s);
}
}
I am having the game crash in my init method when I construct it- ChillServer server = new ChillServer(3377);


Sign In
Create Account


Back to top









