3

I tried some examples of ZMQ on C++,C# and Python. I am trying to have Request-Reply pattern to connect Android device to PC running UWP with Xamarin forms.

Below is the Requestor code:

public void HelloWorld()
{


    var timer = new Timer(60000);
    timer.Start();
    timer.Elapsed += (sender, args) =>
    {
        this.Cancel = true;

        timer.Stop();
    };
    // Create
    const string endpoint = "tcp://PC_ip:3245";
    using (var request = new RequestSocket())
    {
        request.Bind(endpoint);


        Thread.Sleep(2000);
        while (!Cancel)
        {
            request.SendFrame("Requester says hello");
            var reply = request.ReceiveFrameString();
            Debug.WriteLine("Gets reply {0}",reply);
        }
    }

}

Reply socket code:

public void HelloWorld()
{
    var timer = new Timer(60000);
    const string endpoint = "tcp://PC_ip:3245";
    timer.Start();
    timer.Elapsed += (sender, args) =>
    {
        timer.Stop();
        Cancel = true;
    };

    using (var replierSocket = new ResponseSocket())
    {

        replierSocket.Connect(endpoint);
        Thread.Sleep(2000);
        while (!Cancel)
        {
            var replyFromRequester = replierSocket.ReceiveFrameString();
            Debug.WriteLine("Got reply {0}", replyFromRequester);
            replierSocket.SendFrame("Response socket say hello");

        }
    }
}

Cancel is boolean

I went through some questions posted on this and added delay and these connection code blocks only trigger after button clicks on app.

While debugging , request.ReceiveFrameString() replierSocket.ReceiveFrameString(); are not even hit.

I am new to network programming , I understand that for REQ/REP pattern the code has to be in particular order which I traced and fixed I believe and turned off firewall on my PC so that firewall wont block my incoming connections from Android device.

PC_ip stands for IPv4 address I got from ipconfig /all for my wifi. I also tried external ip of my machine from sites like whatsmyip.org at ResponseSocket but I still dont get response between devices.

Please let me know what am I doing wrong.


Issue replication repository : GitHub/me/XamZeroMq

Morse
  • 8,258
  • 7
  • 39
  • 64
  • 1
    First of all, for response socket, try opening the port on all interfaces. (`tcp://*:3245`). Then, install telnet and try to telnet to that port. Let's see if it is open (not using your PC). This helps you a lot. Also please make sure that your UWP app has the following capabilities: "internetClientServer", "privateNetworkClientServer". Also, double check the network address used by the emulator and see how it is connected to your PC. Is it connected to a private internal network or is part of the external network. Your problem is with the environment instead of the code as far as I can see. – Soroush Falahati Feb 01 '19 at 01:16
  • I will cross check these. Thanks. Using physical phone though. – Morse Feb 01 '19 at 15:50

0 Answers0