📄 serverthread.jsl
字号:
锘縫ackage sever;
/**
* Summary description for serverthread.
*/
import java.io.*;
import java.util.*;
import java.net.*;
public class serverthread extends Thread
{
String str;
int a = 0;
Socket clientRequest=null;
BufferedReader in;
PrintWriter out;
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
public serverthread(Socket s,int r) {
this.a = r;
this.clientRequest=s;
try{
out= new PrintWriter(clientRequest.getOutputStream());
}catch(IOException e){}
// out.println("Welcome to the server!");
//out.flush();
System.out.println("Client connected is OK!.");
System.out.println("The Client Address is: "+this.clientRequest.getInetAddress().getHostAddress().toString());
//out.println("Welcome to Server,you are the " + a + " vistor");
//out.flush();
}
public void run(){
out.println("Welcome to Server,you are the " + a + " vistor");
out.flush();
while(true)
{
try{
//out.println("Welcome to the server!");
//out.flush();
in = new BufferedReader(new InputStreamReader(clientRequest.getInputStream()));
str=in.readLine();
} catch(IOException e){}
//out.println("Welcome to Server,you are the " + a + " vistor");
//out.flush();
System.out.println("<"+this.clientRequest.getInetAddress().getHostAddress().toString()+">"+str);
out.println("Message has sent to the server");
out.flush();
if (str.equals("exit")){
System.out.println("Client is Closed!");
break;
}
//try{
//System.out.println("DO you want Close Server: y or any");
// str=input.readLine();
//}catch(IOException e){}
//if(str.equals("y")||str.equals("Y"))
//break;
//System.out.println("Server is waiting for connection");
}
System.out.println("Server closed.");
try{
this.clientRequest.close();
}
catch(IOException e){System.out.println(e.getMessage());}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -