Hello everyone, I am facing problem to establish a socket connection from android device to PC's a specific port like 8080. I just want to create a socket which will connect to the specific port and also write some data stream on that port.
I have written some code for this purpose but the code is giving me an exception as TCP Error:java.net.ConnectException:/127.0.0.1:8080-connection refused
i am giving my code as below:
private static TextView txtSendStatus;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initControls();
    String sentence = "TCP Test #1n";
    String modifiedSentence;
    try {
        Socket clientSocket = new Socket("192.168.18.116", 8080);
        DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
        BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        printScr("TCP Connected.");
        outToServer.writeBytes(sentence + 'n');
        modifiedSentence = inFromServer.readLine();
        printScr(modifiedSentence);
        printScr("TCP Success !!!");
        clientSocket.close();
    } catch (Exception e) {
       printScr("TCP Error: " + e.toString());
    }
} 
private void initControls()
{
      txtSendStatus = (TextView)findViewById(R.id.txtSendStatus);
}
public static void printScr(String message)
{
       txtSendStatus.append( "n" + message );
}
Is there anyone who can tell me the answer? I am waiting for the right answer.
Best Regards, gsmaker