Public void onClick (View v) {
The switch (v.g etId ()) {
Case R.i db tn_lj: //"connect to the server" button
Ur1=et_ IP . The getText (), toString (). The trim ();//get the text information. Leading and trailing Spaces into a string. Cut off the string
Text=et_ port . The getText (), toString (). The trim ();
{if (TextUtils. IsEmpty (ur1))
Toast. MakeText (this, "Ip address can't be empty", Toast. LENGTH_SHORT), show ();
return;
}
{if (TextUtils. IsEmpty (text))
Toast. MakeText (this, "port can't be empty", Toast. LENGTH_SHORT), show ();
return;
}
if (socket!=null & amp; & Socket. IsConnected ()) {//as a condition judgment, to realize the connection is successful and then click the button to disconnect the socket
Try {
Socket. The close ();
The socket=null;//to empty mSocket
S_lj. SetText (" connection ");
Toast. MakeText (MainActivity. This connection has been closed, Toast. LENGTH_LONG), show ();
}
The catch (IOException e) {
e.printStackTrace();
}
}
Dk=Integer. ParseInt (text);//the string "text" into integer
STR="";
New ServerThreadTCP (). The start ();
break;
This program can run, the actual connection to control fan operation, my idea is to click on "connect to the server" button after the APP to establish a socket connection with the ESP8266 module, text button becomes "disconnect" (use handler implementation), when click on this button to disconnect and ESP8266 socket connection, but now the problem is the connection ok, text change ok, is why disconnected button to flash back, when the great god help me analysis analysis, thank you very much!
CodePudding user response:
A flash back, you don't even make up the error log, guess?CodePudding user response:
Socket itself is empty, the socket. IsConnected () newspaper under the null pointer you catch exceptions is IO exceptionCodePudding user response:
Thank you, "connection" threaded programs utility is ok. No other button has been solved, thank you??