Hi!
Ich hab wiedermal ein Problem mit meinem Java Programm. Hier schonmal ein Update von Client.java (hat sich aber nicht viel geändert):
Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class Client
{
private Socket s;
private Thread t;
private BufferedReader in;
private PrintStream out;
private int id;
public Client(Socket cs)
throws IOException
{
s = cs;
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
out = new PrintStream(s.getOutputStream());
id = Integer.parseInt(in.readLine());
start();
}
public int getID()
{
return id;
}
public void sendMessage(String msg)
{
out.print(msg);
}
private void start()
{
RSS.registerPlugin(getID(), this);
t = new Thread(this.new Input());
t.start();
}
private void end()
throws IOException, InterruptedException
{
RSS.unregisterPlugin(getID());
s.close();
t.join();
}
class Input
implements Runnable
{
public void run()
{
try
{
while(true)
{
if(s.isConnected() == true)
{
String input = in.readLine();
int tgid = Integer.parseInt(input.substring(0,2));
String msg = input.substring(2);
RSS.messagePlugin(tgid,msg);
}
else
end();
}
}
catch(IOException e)
{
System.err.println("Client: IOException - " + e.getMessage());
}
catch(InterruptedException e)
{
System.err.println("Client: InterrupedException - " + e.getMessage());
}
}
}
}
Immer wenn sich ein Plugin zum Server connected gibt Client.Input.run() eine IOExcpetion aus: Connection refused.
Der Fehler tritt in dem Block
Code:
if(s.isConnected() == true)
{
String input = in.readLine();
int tgid = Integer.parseInt(input.substring(0,2));
String msg = input.substring(2);
RSS.messagePlugin(tgid,msg);
}
auf. Hat jemand eine Idee wo das Problem liegt?
Gruß Jan
Lesezeichen