我正在尝试执行例程以重新连接套接字,但没有成功。 当我停止并重新启动服务器时,客户端将关闭连接,但是无法重置它。有什么建议吗?
这是一个示例:
private void StartSocket(String IP, String port) {
execsocket = true;
st = new SocketTask(IP, Integer.parseInt(port), 5000) {
@Override
protected void onProgressUpdate(String... progress) {
recived = subst_emoticon(progress[0]);
Log.d("Rec", recived);
String cmd = "";
if (!recived.isEmpty()) {
if (recived.length() >= 4) {
cmd = recived.substring(0, 4);
}
if (cmd.equals("ERRO")) {
String[] parts = recived.split(";");
if (parts[0].equals("ERROR1")) {
if (!Repetir) {
if (MsgBox("No connection", "Working in offline?", "No", "Yes")) {
offline = true;
IP = "0";
Send("!LOG;" + Usuario + ";" + Senha);
} else
finish();
}
}
if (parts[0].equals("ERROR2")) {
if (MsgBox("Lost connection", "Retry?", "No", "Yes")) {
**//Routine for retry connection //**
}
}
}
谢谢!