locked
Windows mobile socket programming issue RRS feed

  • Question

  • Hi huys,

    I am trying to write the server side code on the windows mobile and the client side in a simple console application using sockets (TCPListener and TCPClient), my problem is the error: No connection can be made because the target machine actively refused it. I am using port 8811 and the ip address 127.0.0.1, have added the port to my firewall exceptions and everything is ready, but I get this error.

     

    can you help with that please?

     

    part of the code:

    ////////////Server side: (On windows mobile)/////////

    IPAddress ipAdd = IPAddress.Parse("127.0.0.1");
                TcpListener listener = new TcpListener(ipAdd, 8811);


                //Start Listening
                listener.Start();


                lblWarning.Text = "Server running...";

                while (true)
                {
                    const int bufferSize = 8192;


                    //The server waits until a client makes a request
                    TcpClient client = listener.AcceptTcpClient();
                    NetworkStream clientStream = client.GetStream();

     

    //////////////Client side code (on windows console app)//////////////

    TcpClient client = ConnectToServer();

     private TcpClient ConnectToServer()
            {
                try
                {
                    // Connect to the server.
                    TcpClient client = new TcpClient();

                    //IPHostEntry host = Dns.GetHostEntry("localhost");
                    //var address = (from h in host.AddressList
                    //               where h.AddressFamily == AddressFamily.InterNetwork
                    //               select h).First();

                    IPEndPoint ipE = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8811);
                    client.Connect(ipE);

                    return client;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return null;
                }

           
            }

    Tuesday, December 14, 2010 11:56 PM

Answers

  •  

    Hi Alireza1984,

     

    Welcome to the MSDN forum,  I'm Jesse and I'll be helping you.

     

    I notice that you server running on computer and your client running on mobile, but

    IPEndPoint ipE = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8811);

     

    127.0.0.1 will connect to mobile itself, so I think it will be computer's IP.

     

    If I misunderstood you, please describe your question in more detail.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Monday, December 27, 2010 6:56 AM
    Thursday, December 16, 2010 7:31 AM
  • Hi Alireza1984,

       Welcome to MSDN Forums!  

       This is Brave Zhou; as Jesse said, I would also suggest that, Please Make sure your emulator can connect to internet.

     

       For more information about connection, please refer to:

     

    http://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/51e11802-a8bd-4051-8701-1f1e304fc3ae

    Hope helps, if you have any question feel free to let me know.

    Regards

    Brave

    • Marked as answer by Jesse Jiang Monday, December 27, 2010 6:56 AM
    Friday, December 17, 2010 4:51 AM

All replies

  •  

    Hi Alireza1984,

     

    Welcome to the MSDN forum,  I'm Jesse and I'll be helping you.

     

    I notice that you server running on computer and your client running on mobile, but

    IPEndPoint ipE = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8811);

     

    127.0.0.1 will connect to mobile itself, so I think it will be computer's IP.

     

    If I misunderstood you, please describe your question in more detail.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Monday, December 27, 2010 6:56 AM
    Thursday, December 16, 2010 7:31 AM
  • Hi Alireza1984,

       Welcome to MSDN Forums!  

       This is Brave Zhou; as Jesse said, I would also suggest that, Please Make sure your emulator can connect to internet.

     

       For more information about connection, please refer to:

     

    http://social.msdn.microsoft.com/Forums/en-US/microsoftdeviceemu/thread/51e11802-a8bd-4051-8701-1f1e304fc3ae

    Hope helps, if you have any question feel free to let me know.

    Regards

    Brave

    • Marked as answer by Jesse Jiang Monday, December 27, 2010 6:56 AM
    Friday, December 17, 2010 4:51 AM
  •  

    Hi Alireza1984,

     

    I marked may reply as answer, if you still have any doubts and concerns about this issue, please unmark it and let me know.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 27, 2010 7:15 AM