0

I'm trying to communicate a Windows (C#) software with an Android (Java) application. But Windows is throwing me the following error:

No connection could be made because the target machine actively refused it 192.168.1.3:8222

Windows code (C#)

Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    void button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (!clientSocket.Connected)
                clientSocket.Connect(IPAddress.Parse("192.168.1.3"), 8222); //This is my android ip address

            clientSocket.Send(Encoding.UTF8.GetBytes("Esto es una prueba"));
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

Android code (Java)

    localIPAddr = Utils.getIPAddress(true);// = getLocalIPAddress();

    // Toast.makeText(getApplicationContext(), localIPAddr,
    // Toast.LENGTH_SHORT).show();

    texto.setText(localIPAddr);

    Log.d("Test", localIPAddr);

    new Thread(new Runnable() {
        public void run() {

            while (true) {
                try {
                    if (serverSocket == null) {
                        // No need to get local IP address and to bind InetSocketAddress.
                        // Following single line make it very simple.
                        serverSocket = new ServerSocket(8222, 4);
                        workerSocket = serverSocket.accept();

                        Log.d("Test", "serverSocket == null");

                    }
                    // When data are accepted socketInputStream will be invoked.
                    socketInputStream = new DataInputStream(
                                workerSocket.getInputStream());

                    /* Since data are accepted as byte, all of them will be collected in the
                    following byte array which initialised with accepted data length. */
                    byte[] rvdMsgByte = new byte[socketInputStream.available()];

                    Log.d("Test", "rvdMsgByte: "+rvdMsgByte);

                    // Collecting data into byte array
                    for (int i = 0; i < rvdMsgByte.length; i++)
                        rvdMsgByte[i] = socketInputStream.readByte();

                    // Converting collected data in byte array into String.
                    String rvdMsgTxt = new String(rvdMsgByte);

                    // Setting String to the text view.
                    texto.setText(rvdMsgTxt);
                } catch (Exception ex) {
                }
            }
        }
    });

Maniofest permissions

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Why it says the target machine actively refused it? What am I doing wrong?

EDIT:

Ok I solved the issue of it not connecting. I forgot to add .start(); at the end of the Android Thread so the thread was never executed. But now I'm receiving bytes but no text. Here's the logcat:

    05-09 02:17:31.674: D/Test(2738): rvdMsgByte: [B@41a75468
    05-09 02:17:31.674: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.674: D/Test(2738): rvdMsgByte: [B@41a75708
    05-09 02:17:31.674: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.674: D/Test(2738): rvdMsgByte: [B@41a759a8
    05-09 02:17:31.674: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.674: D/Test(2738): rvdMsgByte: [B@41a75c48
    05-09 02:17:31.674: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.674: D/Test(2738): rvdMsgByte: [B@41a75ee8
    05-09 02:17:31.674: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.674: D/Test(2738): rvdMsgByte: [B@41a76188
    05-09 02:17:31.674: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a76428
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a766c8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a76968
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a76c08
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a76ea8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a77148
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a773e8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a77688
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a77928
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a77bc8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a77e68
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a78108
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a783a8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a78648
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a788e8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a78b88
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a78e28
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a790c8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a79368
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a79608
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a798a8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a79b48
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a79de8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7a088
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7a328
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7a5c8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7a868
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7ab08
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7ada8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7b048
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7b2e8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7b588
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7b828
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7bac8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7bd68
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7c008
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7c2a8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7c548
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7c7e8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7ca88
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7cd28
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7cfc8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7d268
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7d508
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7d7a8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7da48
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7dce8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7df88
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7e228
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7e4c8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7e768
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7ea08
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7eca8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7ef48
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7f1e8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7f488
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7f728
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7f9c8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7fc68
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a7ff08
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a801a8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a80448
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a806e8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a80988
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a80c28
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a80ec8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a81168
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a81408
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a816a8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a81948
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a81be8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a81e88
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a82128
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a823c8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a82668
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a82908
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a82ba8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a82e48
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a830e8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a83388
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a83628
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a838c8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a83b68
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a83e08
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a840a8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a84348
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a845e8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a84888
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a84b28
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a84dc8
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.679: D/Test(2738): rvdMsgByte: [B@41a85068
    05-09 02:17:31.679: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a85308
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a855a8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a85848
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a85ae8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a85d88
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a86028
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a862c8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a86568
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a86808
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a86aa8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a86d48
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a86fe8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a87288
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a87528
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a877c8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a87a68
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a87d08
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a87fa8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a88248
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a884e8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a88788
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a88a28
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a88cc8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a88f68
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a89208
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a894a8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a89748
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a899e8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a89c88
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a89f28
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8a1c8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8a468
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8a708
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8a9a8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8ac48
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8aee8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8b188
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8b428
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8b6c8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8b968
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8bc08
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8bea8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8c148
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8c3e8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8c688
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8c928
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8cbc8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8ce68
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8d108
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8d3a8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8d648
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8d8e8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8db88
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8de28
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8e0c8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8e368
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8e608
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8e8a8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8eb48
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8ede8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8f088
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8f328
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8f5c8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8f868
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8fb08
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a8fda8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a90048
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a902e8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a90588
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a90828
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a90ac8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a90d68
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a91008
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a912a8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a91548
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a917e8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a91a88
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a91d28
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a91fc8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a92268
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a92508
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a927a8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a92a48
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a92ce8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a92f88
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a93228
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a934c8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a93768
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a93a08
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a93ca8
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a93f48
    05-09 02:17:31.684: D/Test(2738): rvdMsgTxt: 
    05-09 02:17:31.684: D/Test(2738): rvdMsgByte: [B@41a941e8
4

2 回答 2

0

好的,我解决了。我很愚蠢。这是工作代码:

窗口 (C#)

Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    void button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (!clientSocket.Connected)
                clientSocket.Connect(IPAddress.Parse("192.168.1.3"), 8222);

            clientSocket.Send(Encoding.UTF8.GetBytes("Esto es una prueba"));
            clientSocket.Disconnect(true);
            clientSocket.Close();
            clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //You need to close the send code
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

安卓 (Java)

private void runTcpServer() {
    ServerSocket ss = null;
    try {
        ss = new ServerSocket(TCP_SERVER_PORT);
        Log.d("TcpServer", ss.getInetAddress()+"");
        //ss.setSoTimeout(10000);
        //accept connections
        Socket s = ss.accept();
        Log.i("TcpServer", "Receiving");
        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        //BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
        //receive a message
        Log.i("TcpServer", in.readLine());
        final String incomingMsg = in.readLine() + System.getProperty("line.separator");
        Log.i("TcpServer", "received: " + incomingMsg);
        runOnUiThread(new Runnable() {
            public void run() {
                texto.append("received: " + incomingMsg);
            }
        });

        s.close();
    } catch (InterruptedIOException e) {
        //if timeout occurs
        e.printStackTrace();
        Log.e("TcpServer", ""+e);
    } catch (IOException e) {
        e.printStackTrace();
        Log.e("TcpServer", ""+e);
    } finally {
        if (ss != null) {
            try {
                ss.close();
            } catch (IOException e) {
                e.printStackTrace();
                Log.e("TcpServer", ""+e);
            }
        }
    }
}
于 2013-05-09T06:51:55.180 回答
0

确保 users-permission 行位于应用程序标记之外

于 2013-05-09T05:41:06.247 回答