Home > other >  Java socket in the client and the server to transmit data
Java socket in the client and the server to transmit data

Time:10-18

Data transmission time has been hung thread processing not over how be to return a responsibility?

CodePudding user response:

Public static String sends (byte [] SCR) {
The Socket client=null;
InputStream in=null;
OutputStream out=null;
String MSG=null;
Boolean Ming=false;
If (client==null) {


Try {
The client=new Socket (" 192.168.7.1 ", 4622);
{} the catch (UnknownHostException e2)
//TODO Auto - generated the catch block,
E2. PrintStackTrace ();
{} the catch (IOException e2)
//TODO Auto - generated the catch block,
E2. PrintStackTrace ();
}
Try {
Client. SetSoTimeout (3000);
In=client. GetInputStream ();
Out=client. GetOutputStream ();
Out. Write (SCR);
Client. SetSoTimeout (5 * 5000);
out.flush();
Int count=0;
While (count==0) {
Count=in. The available ();

}
Byte [] buffer=new byte (count);
In the read (buffer);
MSG=bytes2HexString (buffer);


} the catch (IOException e) {
//TODO Auto - generated the catch block,
Try {
Client. The close ();
{} the catch (IOException e1)
//TODO Auto - generated the catch block,
E1. PrintStackTrace ();
}
}


The finally {
If (client!=null) {
Try {

Client. The close ();
Client. IsConnected ();

} the catch (IOException e) {
//TODO Auto - generated the catch block,
The client=null;
}
}

}
}

Return MSG.

}
Just paste the code

CodePudding user response:

Every time I click on the button will be called a side this class
  • Related