Java.net.SocketException连接重置GPS

时间:2012-07-27 20:35:01

标签: gps connection reset

我知道这个问题已被提出,但给予该人的答案是使用read(),直到EOF。我应用了这个答案,我的服务器仍然发送“连接重置”。对于那些不熟悉问题的人,我正在尝试将安装在我车内的GPS连接到我的服务器。它适用于SMS和GPRS命令,因此我们的想法是成功连接设备。这是代码:

这是我的客户套管经理

package tcp.clientservermodel;

import java.net.*;
import java.io.*;


public class ClientSocketManager extends Thread{

    Socket client_socket_;
    InputStream input_;
    OutputStream output_;
    ClientSocketCaller caller_;

    public ClientSocketManager( ClientSocketCaller caller,Socket incoming_socket){
        this.caller_=caller;
        this.client_socket_=incoming_socket;
        this.start();
    }

    public void run(){
        try{
            input_=this.client_socket_.getInputStream();
            output_=this.client_socket_.getOutputStream();
            int incoming_char=0;
            StringBuffer incoming_message=new StringBuffer();
            while((incoming_char=input_.read())!=-1){
           //     System.out.println(incoming_message.toString());
                    if(incoming_char=='\n'){ ProcessMessage(this. client_socket_.getInetAddress().toString()+": "+incoming_message.toString());
                    incoming_message=new StringBuffer();
                }else{
                    incoming_message.append((char)incoming_char);
                }
            }
        }catch(Exception err){

        }
    }

    public boolean SendMessage(String message){
        boolean success=true;
        try{
           this.output_.write(("123456G").getBytes());
        }catch(Exception err){
            success=false;
        }
        return success;
    }

    public void ProcessMessage(String message){
        System.out.println(message);
        caller_.MessageHasBeenRecieved(message);
    }

}

SERVER SOCKET MANAGER:

package tcp.clientservermodel;

import java.net.*;
import java.io.*;
import java.util.*;

public class ServerSocketManager extends Thread
        implements ClientSocketCaller{

    int port_;
    ServerSocket server_socket_;
    public boolean is_enabled_=true;
    Vector client_sockets_vector_=new Vector();

    public ServerSocketManager(int port){
        this.port_=port;
        this.start();
    }

    public void run(){
        try{
            this.server_socket_=new ServerSocket(port_);

            while(is_enabled_){
                Socket client_socket=this.server_socket_.accept();
                System.out.println("Connection Succesful "+client_socket.getInetAddress().toString());
                this.client_sockets_vector_.add(new ClientSocketManager(this,client_socket));
            }
        }catch(Exception err){
            System.out.println(err +"   3");
        }
    }

    public void MessageHasBeenRecieved(String message) {
        for(int i=0;i<this.client_sockets_vector_.size();i++){
            ClientSocketManager current=(ClientSocketManager)this.client_sockets_vector_.get(i);
            if(current!=null){
                current.SendMessage(message);
            }
        }
    }

}

这是客户插座电话

package tcp.clientservermodel;


public interface ClientSocketCaller {

    public void MessageHasBeenRecieved(String message);

}

错误位于此行

(incoming_char = input_.read())!= - 1

,输出

java.net.SocketException连接重置

请我帮忙!

1 个答案:

答案 0 :(得分:0)

我解决了问题...我使用Wireshark查看服务器和GPS之间的包。所以我注意到Wireshark中“win”参数的大小在两个流之间是不同的。从GPS =&gt; win = 10880,并且来自server =&gt; win = 8019.我只是改变服务器的win元素并且工作!!!!