TheJediCowboy
TheJediCowboy

Reputation: 9232

ZeroMQ C# HelloWorld Example

Out of curiosity, I decided to run through a couple of the examples in the ZeroMQ library. Specifically, the "Hello World" example at http://zguide.zeromq.org/cs:hwclient

To me knowledge I have copied the code from the example correctly, and I have the following:

public class Program
{
    public static void Main(string[] args)
    {
        using(var context = new Context(1))
        {
            using(Socket requester = context.Socket(SocketType.REQ))
            {
                requester.Connect("tcp://localhost:5555");

                const string requestMessage = "Hello";
                const int requestsToSend = 10;

                for(int requestNumber = 0; requestNumber < requestsToSend;requestNumber++)
                {
                    Console.WriteLine("Sending Request {0}...", requestNumber);
                    requester.Send(requestMessage,Encoding.Unicode);

                    string reply = requester.Recv(Encoding.Unicode);
                    Console.WriteLine("Received Reply {0}: {1}", requestNumber, reply);
                }
            }
        }

        Console.ReadLine();

    }

}

The problem I am experience is that once it hits the following line, the program just stops and waits for the message, and it seems to never receive it.

string reply = requester.Recv(Encoding.Unicode);

The program gets caught up on this line. I would imagine this possibly has to do with conflicting tcp address? Not really sure as I am not too seasoned in socket level programming.

Any ideas on why this wouldn't be working? I have searched the ZeroMQ documentation, but haven't come up with anything as of yet.

Upvotes: 1

Views: 3467

Answers (1)

Jeff Watkins
Jeff Watkins

Reputation: 6357

Note how it's called "HWClient". There is a Hello World Server side too. You should run that up first.

Upvotes: 4

Related Questions