title: How to use ZMQ when Server on IP other than the client
body: <p>I learned how to use <strong><code>ZeroMQ</code></strong> on a <code>localhost</code>, but I failed to do it on a remote IP.</p>
  
  <p><strong><code>Q1:</code></strong> Do I need a broker?<br>If so,<br><strong><code>Q2:</code></strong> which broker and how to do it.?</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>OK. I'm using the <code>ZMQ</code> Weather Update example but with a remote IP ( not the <code>localhost</code> ). Here is what I do using <code>C# ZMQ</code> bindings ( however, I'm OK to use any other language ):</p>
  
  <p>ZMQ <strong>Server:</strong></p>
  
  <pre><code>using (var context = new ZContext())
  using (var publisher = new ZSocket(context, ZSocketType.PUB))
  {
      string address = "tcp://*:5001";
  
      publisher.Bind(address);
  
      publisher.Send("msg")
  }
  </code></pre>
  
  <p><strong>Proxy:</strong></p>
  
  <pre><code>using (var context  = new ZContext())
  using (var frontend = new ZSocket(context, ZSocketType.XSUB))
  using (var backend  = new ZSocket(context, ZSocketType.XPUB))
  {
      // Frontend is where the weather server sits
      string localhost = "tcp://127.0.0.1:5001";
      Console.WriteLine("I: Connecting to {0}", localhost);
  
      frontend.Connect(localhost);
  
      // Backend is our public endpoint for subscribers
      string remoteIP = "216.123.23.98";                          // For example
      var tcpAddress = string.Format("tcp://{0}:8100", remoteIP); // I also tried localhost address here
  
      Console.WriteLine("I: Binding on {0}", tcpAddress);
  
      backend.Bind(tcpAddress);
  
      var epgmAddress = string.Format("epgm://localhost;{0}:8100", remoteIP);
  
      Console.WriteLine("I: Binding on {0}", epgmAddress);
  
      backend.Bind(epgmAddress);
  
      using (var subscription = ZFrame.Create(1))
      {
          subscription.Write(new byte[] { 0x1 }, 0, 1);
          backend.Send(subscription);
      }
  
      // Run the proxy until the user interrupts us
      ZContext.Proxy(frontend, backend);
  }
  </code></pre>
  
  <p><strong>Client:</strong></p>
  
  <pre><code>using (var context    = new ZContext())
  using (var subscriber = new ZSocket(context, ZSocketType.SUB))
  {
      string remoteIP = "tcp://216.123.23.98";              //For example
      Console.WriteLine("I: Connecting to {0}…", remoteIP);
  
      subscriber.Connect(connect_to);
  
      // Subscribe to zipcode
      string zipCode = args[0];
      Console.WriteLine("I: Subscribing to zip code {0}…", zipCode);
  
      subscriber.Subscribe(zipCode);
  
      // Process 10 updates
      int i = 0;
      long total_temperature = 0;
      for (; i &lt; 20; ++i)
      {
          ZError err;
          using (var replyFrame = subscriber.ReceiveFrame(out err))
          {
              string reply = replyFrame.ReadString(Encoding.ASCII);
  
              Console.WriteLine(reply);
              total_temperature += Convert.ToInt64(reply.Split(' ')[1]);
          }
      }
      Console.WriteLine("Average temperature for zipcode '{0}' was {1}", zipCode, (total_temperature / i));
  }
  </code></pre>
  
  <p>When I run this I get error in <strong>Server</strong> and error in <strong>proxy</strong> - server gets </p>
  
  <blockquote>
    <p><code>Invalid end point</code></p>
  </blockquote>
  
  <p>and proxy gets <code>EINVAL(22)</code>:</p>
  
  <blockquote>
    <p><code>Invalid argument   at ZeroMQ.ZSocket.Bind(String endpoint)</code></p>
  </blockquote>