📄 userthread.java
字号:
import java.io.*;
import java.net.*;
public class UserThread extends Thread
{
protected DataInputStream inStream;
protected DataOutputStream outStream;
protected Socket socket;
public UserThread(Socket socket)
{
try
{
this.socket=socket;
inStream=new DataInputStream(socket.getInputStream());
outStream=new DataOutputStream(socket.getOutputStream());
sendString("我是客户机!");
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
public void run()
{
String str=null;
try
{
while(true)
{
str=inStream.readUTF();
dataProcess(str);
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
finally
{
try
{
socket.close();
}
catch(IOException e1)
{
System.out.println(e1.toString());
}
}
}
public void dataProcess(String msg)
{
System.out.println("客户机接受到数据:"+msg);
}
public void sendString(String msg) throws IOException
{
outStream.writeUTF(msg);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -