📄 nclithread.java
字号:
import java.io.*;
import java.net.*;
public class nclithread extends Thread
{ Socket socket;
int threadNumber;
public nclithread(int i,Socket s)
{ threadNumber=i;
socket=s;
start();
}
public void run()
{
try {
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),true);
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
String str1=in.readLine();
System.out.println("Question from Server: "+str1);
out.println("Thread "+threadNumber+"'s time is 21:05");
String str2=in.readLine();
System.out.println("Receive from Server: "+str2);
}
catch(IOException e)
{ System.err.println("IO Exception");
}
finally{
System.out.println("Closing ...");
try
{socket.close();}
catch(IOException e)
{System.err.println("Socket not closed");}
}
}
public static void main(String[] args)throws IOException
{
InetAddress addr=InetAddress.getByName(null);
Socket socket1=new Socket(addr,4000);
Socket socket2=new Socket(addr,4000);
new clithread(1,socket1);
new clithread(2,socket1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -