继承Thread 类 可以不重写run()方法吗?
这个好像没有public void run()方法啊!
客户端创建实例化了10个客户端,每个客户端都向服务器发送请求,并接收服务器返回 的请求!
import java.io.*;
import java.net.*;
class SocketThreadClient extends Thread
{
public static int count = 0;
public SocketThreadClient (InetAddress addr)
{
count++;
BufferedReader in = null;
PrintWriter out = null;
Socket sk = null;
try{
sk = new Socket (addr, 8000);
InputStreamReader isr;
isr = new InputStreamReader (sk.getInputStream ());
in = new BufferedReader (isr);
out = new PrintWriter (new BufferedWriter(new OutputStreamWriter(sk.getOutputStream ())), true);
System.out.println("count:"+count);
out.println ("Hello");
System.out.println (in.readLine ());
out.println ("BYE");
System.out.println (in.readLine ());
}
catch (IOException e)
{
System.out.println (e.toString ());
}
finally
{
out.println("END");
try
{
if (in != null)
in.close ();
if (out != null)
out.close ();
if (sk != null)
sk.close ();
}
catch (IOException e)
{
}
}
}
}
public class SocketClient{
public static void main(String[] args) throws IOException,InterruptedException
{
InetAddress addr = InetAddress.getByName(null);
for(int i=0;i<10;i++)
new SocketThreadClient(addr);
Thread.currentThread().sleep(1000);
}
}