代码:
elaur@colossus[~]$ cat irc.java
import java.net.*;
import java.io.*;
class irc
{
static Socket server;
static BufferedReader in;
static BufferedReader stdin;
static PrintWriter out;
public static void main(String args[])
{
String user_line;
try
{
server = new Socket(args[0], 6667);
in = new BufferedReader( newInputStreamReader(server.getInputStream()) );
stdin = new BufferedReader( newInputStreamReader(System.in) );
out = new PrintWriter(server.getOutputStream());
}
catch (UnknownHostException e) {}
catch (IOException e) {}
irc_in input = new irc_in(server, out, stdin);
Thread t = new Thread(input);
t.run();
while (true)
{
try {
System.out.println(in.readLine());
System.out.flush();
Thread.sleep(2000);
} catch (IOException e) {}
catch (InterruptedException e) {}
}
}
}
class irc_in implements Runnable
{
static Socket server;
static PrintWriter out;
static BufferedReader stdin;
irc_in(Socket a, PrintWriter b, BufferedReader c)
{
server = a;
out = b;
stdin = c;
}
public void run()
{
String user_line;
while (true)
{
try
{
Thread.sleep(1000);
user_line = stdin.readLine();
System.out.println("Got: " + user_line);
out.println(user_line);
out.flush();
}
catch (IOException e) {}
catch (InterruptedException e) {}
}
}
}
我可以发送输入,但我无法在我的屏幕上获得任何输出。有任何想法吗?