I have an app that communicates with a piece of hardware over port 22. The app worked up until this month. Now, whenever the app tries to connect to the hardware I receive a socket communication error, and the program ends up crashing because the socket could not be connected.
W/System.err: java.net.SocketException: Software caused connection abort
The only thing I can think of that has changed is that I ran the latest android update on my phone. The code for the hardware has been the same code that I have been testing for the last several months, and the code for the app has been pretty much finalized since the end of March. Did something change in the latest update that could be causing the socket exception?
The socket communication is managed by a service. The code that sets it up is:
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand");
super.onStartCommand(intent, flags, startId);
if (CheckConnectionStatus()){
ConnectSocket();
Log.i(TAG, "Connected To ATP");
} else {
Log.i(TAG, "Not Connected To ATP");
}
return START_STICKY;
}
/*******************************************************************************
*
* Check if phone is connected to ATP
*/
public Boolean CheckConnectionStatus(){
//if connected to proper network, change indicators
String ssid = "";
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if(wifiInfo.getSupplicantState() == SupplicantState.COMPLETED){
ssid = wifiInfo.getSSID();
}
String networkSSID = "\"ATP45\"";
return ssid.equals(networkSSID);
}
/***********************************************************************
* Setup the socket connection
*/
public void ConnectSocket(){
Log.i(TAG, "Running ConnectSocket");
socket = new Socket();
Runnable connectSocket = new SetUpSocketConnection();
communicationThread = new CommunicationThread();
new Thread(connectSocket).start();
}
/**********************************************************************
* Thread to open socket communication
*/
private class SetUpSocketConnection implements Runnable{
@Override
public void run(){
try{
//ERROR IS HERE:
socket.connect(new InetSocketAddress(IP_ADDRESS, PORT));
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
socket.setSoTimeout(800);
inputStream = socket.getInputStream();
reader = new BufferedReader(new InputStreamReader(inputStream), 1000);
Log.d(TAG, "Connected to Socket");
communicationThreadRunning = true;
new Thread(communicationThread).start();
} catch (IOException e){
e.printStackTrace();
}
}
}
EDIT: The line causing the error is where the socket is first connected:
socket.connect(new InetSocketAddress(IP_ADDRESS, PORT));
EDIT 2: Full Stack Trace
W/System.err: java.net.SocketException: Software caused connection abort
W/System.err: at java.net.PlainSocketImpl.socketConnect(Native Method)
W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
W/System.err: at java.net.Socket.connect(Socket.java:586)
W/System.err: at java.net.Socket.connect(Socket.java:535)