?? 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 + -