public class InOutDataService implements InitializingBean and Runnable {
The @autowired
SysIOMapper SysIOMapper;
Private Logger Logger=Logger. GetLogger (enclosing getClass ());
Private static final int PORT=10101;
Private static ServerSocket ServerSocket.
Private static Boolean isStartServer=false;
Private static Socket client;
Private static BufferedReader reader;
@ Override
Public void afterPropertiesSet () throws the Exception {
New Thread (this). The start ();
}
@ Override
Public void the run () {
While (true) {
System. The out. Println (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- start now -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "+ DateUtils. GetDateStr (DateUtils. DATETIMESHOWFORMAT));
Try {
ServerSocket=new serverSocket (PORT);
The client=serverSocket. The accept ();
} the catch (IOException e) {
e.printStackTrace();
}
IsStartServer=true;
While (isStartServer) {
Try {
ListList=null;
Reader=new BufferedReader (new InputStreamReader (client. GetInputStream ()));
String MSG=reader. ReadLine ();
If (MSG!=null) {
System. The out. Println (MSG);
String msg1;
//this code to handle the message
}
//Thread. Sleep (10000);
} the catch (Exception e) {
Logger. Error (um participant etMessage ());
Try {
Reader. The close ();
Client. The close ();
ServerSocket. Close ();
IsStartServer=false;
Thread.sleep (1000);
{} the catch (IOException | InterruptedException e1)
Logger. Error (um participant etMessage ());
E1. PrintStackTrace ();
}
Logger. Error (um participant etMessage ());
e.printStackTrace();
}
}
}
}
}
CodePudding user response:
Is that service program is receiving data, and then about 1 days are normal, suddenly a mental note time is less than the data, if there is something wrong with the code, the great god, please grant instructionCodePudding user response:
Never make, shaking hands is interrupted, you can connect againCodePudding user response:
Give you a possible, for reference,There is a network firewall, Anti - DDOS, WAF safety protective equipment, such as if it have any restrictions on the long link, may be forced off the end of the
CodePudding user response: