package com.linux.vntcenter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class VNTCenter {
/**
* @param args
*/
public static final int SERVER_PORT=2010;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("VNTCenter.main()===TCP SERVER==============");
try{
ServerSocket vntServer= new ServerSocket(SERVER_PORT);
System.out.println("Listening Port is "+vntServer.getLocalPort()+"...");
while(true){
Socket vntClient=vntServer.accept();
System.out.println("have a client entering , the IP is "+vntClient.getInetAddress()+"...");
System.out.println("have a client entering , the Port is "+vntClient.getPort()+"...");
new GetGpsThreadFun(vntClient).start();
}
//vntClient.close();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
class GetGpsThreadFun extends Thread{
private Socket vntThreadClient;
public GetGpsThreadFun(Socket vntThreadSocket){
vntThreadClient=vntThreadSocket;
}
public void run(){
try{
BufferedReader vntThreadIS=new BufferedReader(new InputStreamReader(vntThreadClient.getInputStream()));
while(true){
String vntReceiveString=vntThreadIS.readLine();
if (vntReceiveString!=null){
System.out.println(vntThreadClient.getInetAddress()+":"+vntThreadClient.getPort()+":"+vntReceiveString);
}
if("shutdown".equals(vntReceiveString)){
break;
}
}
vntThreadIS.close();
vntThreadClient.close();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
|