Skip to content

Commit

Permalink
Merge pull request #574 from metadings/master
Browse files Browse the repository at this point in the history
Update on C# Examples
  • Loading branch information
hintjens committed Aug 2, 2015
2 parents 6b502a1 + 10564bd commit f5fb144
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
20 changes: 15 additions & 5 deletions examples/C#/psenvpub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,32 @@ public static void PSEnvPub(string[] args)
publisher.Linger = TimeSpan.Zero;
publisher.Bind("tcp://*:5563");

int published = 0;
while (true)
{
// Write two messages, each with an envelope and content

using (var message = new ZMessage())
{
message.Add(new ZFrame("A"));
message.Add(new ZFrame("We don't want to see this"));
published++;
message.Add(new ZFrame(string.Format("A {0}", published)));
message.Add(new ZFrame(string.Format(" We don't like to see this.")));
Thread.Sleep(1000);

Console_WriteZMessage("Publishing ", message);
publisher.Send(message);
}

using (var message = new ZMessage())
{
message.Add(new ZFrame("B"));
message.Add(new ZFrame("We would like to see this"));
published++;
message.Add(new ZFrame(string.Format("B {0}", published)));
message.Add(new ZFrame(string.Format(" We do like to see this.")));
Thread.Sleep(1000);

Console_WriteZMessage("Publishing ", message);
publisher.Send(message);
}
Thread.Sleep(1000);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion examples/C#/psenvsub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ public static void PSEnvSub(string[] args)
subscriber.Connect("tcp://127.0.0.1:5563");
subscriber.Subscribe("B");

int subscribed = 0;
while (true)
{
using (ZMessage message = subscriber.ReceiveMessage())
{
subscribed++;

// Read envelope with address
string address = message[0].ReadString();

// Read message contents
string contents = message[1].ReadString();

Console.WriteLine("[{0}] {1}", address, contents);
Console.WriteLine("{0}. [{1}] {2}", subscribed, address, contents);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion examples/C#/suisnail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public static void SuiSnail(string[] args)
subpipe.Frontend.ReceiveFrame();
pubpipe.Frontend.Send(new ZFrame("break"));

Thread.Sleep(5000);
// wait for the Thread (you'll see how fast it is)
pubpipe.Join(5000);
}
}
}
Expand Down

0 comments on commit f5fb144

Please sign in to comment.