I am unfortunately having a problem connecting to a TCP server I put together. The server is fairly sophisticated but the connection, disconnection and data transition protocols are fairly simple. The server has been tested by a number of different clients both written in Java and C#. The server itself runs on C# using the standard Microsoft TCPClient and TcpListener classes in order to facilitate connection. I cant say much about what the TCP server does, just that there has to be a side which allows connections from peripheral. It is necessary that the server be able to feed data to connected network peripherals running android, including cellphones and tablets.
For testing purposes I am connecting to the current port which handles the current data feed. Nothing is connected to that port, this is a test version of the server which runs separate from the actual production server. I cannot expose to you the server side code unfortunately.
The following code is what is currently running off a cellphone. It should establish a simple TCP connection to the sever after which the server kills the connection due to a failed handshake. The server lets me know if something is connected and whether or not a handshake has gone through. The following code WORKS (network part at least) when executed on a windows machine but fails to establish a connection when utilized on an android phone. Tested with both wifi aswell as the network provided internet.
public void onClick(View view)
serverIP = ipAddressTextArea.getText().toString();//we can assume this is a valid IP
messages = Toast.makeText(getApplicationContext(), "Attempting to Connect To Server...", Toast.LENGTH_SHORT);
LittleEndianDataOutputStream writter = null;
Socket testTCPSocket = null;
// TODO code application logic here
testTCPSocket = new Socket(serverIP, *******); //Sorry guys cant provide this information
writter = new LittleEndianDataOutputStream(testTCPSocket.getOutputStream()); //Guava
writter.writeInt(200); //Invalid handshake so server doesn't keep waiting for one
} catch (Exception ex)
messages = Toast.makeText(getApplicationContext(), "Attempt Failed...", Toast.LENGTH_SHORT);
I haven't programmed in Java for years and this is my first swing at Android. I am a network programmer coming from C# and C++, so be patient with me on the android side. Remember, this code is a simple test nothing more, so don't yell at me for providing you with code that doesn't do anything.