Skip to content

Commit

Permalink
Fixed some more errors and accidental global replace mistake. Added .…
Browse files Browse the repository at this point in the history
…gitignore to stop the project I'm using to test from getting included.
  • Loading branch information
tjrobinson committed Dec 23, 2012
1 parent 5ff6827 commit 61f0831
Show file tree
Hide file tree
Showing 61 changed files with 248 additions and 2,819 deletions.
8 changes: 8 additions & 0 deletions examples/C#/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
packages
packages.config
bin/
obj/
*.csproj
*.sln
*.suo
*.user
10 changes: 10 additions & 0 deletions examples/C#/ZHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,15 @@ public static void Dump(ZmqSocket socket, Encoding encoding)
Console.WriteLine("{0}", encoding.GetString(frame.Buffer));
}
}

public static void SetID(ZmqSocket client, Encoding unicode)
{
throw new NotImplementedException();
}

public static bool Version()
{
throw new NotImplementedException();
}
}
}
24 changes: 12 additions & 12 deletions examples/C#/asyncsrv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// While this example runs in a single process, that is just to make
// it easier to start and stop the example. Each task has its own
// ZmqContext and conceptually acts as a separate process.
// context and conceptually acts as a separate process.

// Author: Michael Compton, Tomas Roos
// Email: michael.compton@littleedge.co.uk, ptomasroos@gmail.com
Expand All @@ -15,7 +15,7 @@
using ZeroMQ;
using zguide;

namespace ZMQGuide
namespace zguide.asycnsrv
{
internal class Program
{
Expand Down Expand Up @@ -52,9 +52,9 @@ public static void ClientTask()
string identity = client.IdentityToString(Encoding.Unicode);
client.Connect("tcp://localhost:5570");

client.PollInHandler += (ZmqSocket, revents) =>
client.PollInHandler += (socket, revents) =>
{
var zmsg = new ZMessage(ZmqSocket);
var zmsg = new ZMessage(socket);
Console.WriteLine("{0} : {1}", identity, zmsg.BodyToString());
};

Expand Down Expand Up @@ -94,19 +94,19 @@ private static void ServerTask()
for (int workerNumber = 0; workerNumber < 5; workerNumber++)
{
workers.Add(new Thread(ServerWorker));
workers[workerNumber].Start(ZmqContext);
workers[workerNumber].Start(context);
}

// Switch messages between frontend and backend
frontend.PollInHandler += (ZmqSocket, revents) =>
frontend.PollInHandler += (socket, revents) =>
{
var zmsg = new ZMessage(ZmqSocket);
var zmsg = new ZMessage(socket);
zmsg.Send(backend);
};

backend.PollInHandler += (ZmqSocket, revents) =>
backend.PollInHandler += (socket, revents) =>
{
var zmsg = new ZMessage(ZmqSocket);
var zmsg = new ZMessage(socket);
zmsg.Send(frontend);
};

Expand All @@ -122,16 +122,16 @@ private static void ServerTask()

// Accept a request and reply with the same text a random number of
// times, with random delays between replies.
private static void ServerWorker(object ZmqContext)
private static void ServerWorker(object context)
{
var randomizer = new Random(DateTime.Now.Millisecond);
using (ZmqSocket worker = ((ZmqContext)ZmqContext).CreateSocket(SocketType.DEALER))
using (ZmqSocket worker = ((ZmqContext)context).CreateSocket(SocketType.DEALER))
{
worker.Connect("inproc://backend");

while (true)
{
// The DEALER ZmqSocket gives us the address envelope and message
// The DEALER socket gives us the address envelope and message
var zmsg = new ZMessage(worker);
// Send 0..4 replies back
int replies = randomizer.Next(5);
Expand Down
4 changes: 2 additions & 2 deletions examples/C#/clonecli1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
using System.Text;
using ZeroMQ;

namespace ZMQGuide
namespace zguide.clonecli1
{
internal class Program26
internal class Program
{
public static void Main(string[] args)
{
Expand Down
6 changes: 3 additions & 3 deletions examples/C#/clonesrv1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
using System.Threading;
using ZeroMQ;

namespace ZMQGuide
namespace zguide.clonesrv1
{
internal class Program29
internal class Program
{
public static void Main(string[] args)
{
using (var context = ZmqContext.Create())
{
using (var publisher = ZmqContext.CreateSocket(SocketType.PUB))
using (var publisher = context.CreateSocket(SocketType.PUB))
{
publisher.Bind("tcp://*:5556");
Thread.Sleep(TimeSpan.FromMilliseconds(200));
Expand Down
6 changes: 3 additions & 3 deletions examples/C#/hwclient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Hello World client
// Connects REQ ZmqSocket to tcp://localhost:5555
// Connects REQ socket to tcp://localhost:5555
// Sends "Hello" to server, expects "World" back
//

Expand All @@ -11,9 +11,9 @@
using System.Text;
using ZeroMQ;

namespace ZMQGuide
namespace zguide.hwclient
{
internal class Program25
internal class Program
{
public static void Main(string[] args)
{
Expand Down
6 changes: 3 additions & 3 deletions examples/C#/hwserver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Hello World server
// Binds REP ZmqSocket to tcp://*:5555
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//

Expand All @@ -12,9 +12,9 @@
using System.Threading;
using ZeroMQ;

namespace ZMQGuide
namespace zguide.hwserver
{
internal class Program28
internal class Program
{
public static void Main(string[] args)
{
Expand Down
6 changes: 3 additions & 3 deletions examples/C#/identity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
using ZeroMQ;
using zguide;

namespace ZMQGuide
namespace zguide.identity
{
internal class Program3
internal class Program
{
public static void Main(string[] args)
{
Expand All @@ -29,7 +29,7 @@ public static void Main(string[] args)
// Then set the identity ourselves
identified.StringToIdentity("PEER2", Encoding.Unicode);
identified.Connect("inproc://example");
identified.Send("ROUTER ZmqSocket uses REQ's ZmqSocket identity", Encoding.Unicode);
identified.Send("ROUTER socket uses REQ's socket identity", Encoding.Unicode);
ZHelpers.Dump(sink, Encoding.Unicode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/C#/interrupt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
using System.Threading;
using ZeroMQ;

namespace ZMQGuide
namespace zguide.interrupt
{
internal class Program12
internal class Program
{

public static void Main(string[] args)
Expand Down
2 changes: 1 addition & 1 deletion examples/C#/kvsimple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

using ZeroMQ;

namespace ZMQGuide
namespace zguide
{
public class KvMsg
{
Expand Down
26 changes: 13 additions & 13 deletions examples/C#/lbbroker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// While this example runs in a single process, that is just to make
// it easier to start and stop the example. Each thread has its own
// ZmqContext and conceptually acts as a separate process.
// context and conceptually acts as a separate process.
//

// Author: Michael Compton, Tomas Roos
Expand All @@ -17,9 +17,9 @@
using System.Threading;
using zguide;

namespace ZMQGuide
namespace zguide.lbbroker
{
internal class Program37
internal class Program
{
public static void Main(string[] args)
{
Expand Down Expand Up @@ -56,23 +56,23 @@ public static void Main(string[] args)
var workerQueue = new Queue<string>();

// Handle worker activity on backend
backend.PollInHandler += (ZmqSocket, revents) =>
backend.PollInHandler += (socket, revents) =>
{
// Queue worker address for LRU routing
string workerAddress = ZmqSocket.Receive(Encoding.Unicode);
string workerAddress = socket.Receive(Encoding.Unicode);
workerQueue.Enqueue(workerAddress);
// Second frame is empty
string empty = ZmqSocket.Receive(Encoding.Unicode);
string empty = socket.Receive(Encoding.Unicode);
// Third frame is READY or else a client reply address
string clientAddress = ZmqSocket.Receive(Encoding.Unicode);
string clientAddress = socket.Receive(Encoding.Unicode);
// If client reply, send rest back to frontend
if (!clientAddress.Equals("READY"))
{
empty = ZmqSocket.Receive(Encoding.Unicode);
string reply = ZmqSocket.Receive(Encoding.Unicode);
empty = socket.Receive(Encoding.Unicode);
string reply = socket.Receive(Encoding.Unicode);
frontend.SendMore(clientAddress, Encoding.Unicode);
frontend.SendMore();
frontend.Send(reply, Encoding.Unicode);
Expand All @@ -81,13 +81,13 @@ public static void Main(string[] args)
}
};

frontend.PollInHandler += (ZmqSocket, revents) =>
frontend.PollInHandler += (socket, revents) =>
{
// Now get next client request, route to LRU worker
// Client request is [address][empty][request]
string clientAddr = ZmqSocket.Receive(Encoding.Unicode);
string empty = ZmqSocket.Receive(Encoding.Unicode);
string request = ZmqSocket.Receive(Encoding.Unicode);
string clientAddr = socket.Receive(Encoding.Unicode);
string empty = socket.Receive(Encoding.Unicode);
string request = socket.Receive(Encoding.Unicode);
backend.SendMore(workerQueue.Dequeue(), Encoding.Unicode);
backend.SendMore();
Expand Down
12 changes: 6 additions & 6 deletions examples/C#/lbbroker2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// While this example runs in a single process, that is just to make
// it easier to start and stop the example. Each thread has its own
// ZmqContext and conceptually acts as a separate process.
// context and conceptually acts as a separate process.
//

// Author: Michael Compton, Tomas Roos
Expand All @@ -17,9 +17,9 @@
using System.Threading;
using zguide;

namespace ZMQGuide
namespace zguide.lbbroker2
{
internal class Program36
internal class Program
{

private static void ClientTask()
Expand Down Expand Up @@ -56,7 +56,7 @@ public static void Main(string[] args)
var workers = new List<Thread>();
var clients = new List<Thread>();

// Prepare our ZmqContext and sockets
// Prepare our context and sockets
using (var ctx = ZmqContext.Create())
{
using (ZmqSocket frontend = ctx.CreateSocket(SocketType.ROUTER), backend = ctx.CreateSocket(SocketType.ROUTER))
Expand All @@ -65,13 +65,13 @@ public static void Main(string[] args)
backend.Bind("tcp://*:5556");

int clientId;
for (clientId = 0; clientId < clients; clientId++)
for (clientId = 0; clientId < Program.clients; clientId++)
{
clients.Add(new Thread(ClientTask));
clients[clientId].Start();
}

for (int workerId = 0; workerId < workers; workerId++)
for (int workerId = 0; workerId < Program.workers; workerId++)
{
workers.Add(new Thread(WorkerTask));
workers[workerId].Start();
Expand Down
12 changes: 6 additions & 6 deletions examples/C#/lpclient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
using System.Threading;
using ZeroMQ;

namespace ZMQGuide
namespace zguide.lpclient
{
internal class Program24
internal class Program
{
private static int requestTimeout = 2500;
private static int requestRetries = 3;
Expand All @@ -23,13 +23,13 @@ internal class Program24
private static bool expectReply = true;
private static int retriesLeft = requestRetries;

private static ZmqSocket CreateServerSocket(ZmqContext ZmqContext)
private static ZmqSocket CreateServerSocket(ZmqContext context)
{
Console.WriteLine("Connecting to server...");

var client = context.CreateSocket(SocketType.REQ);
client.Connect(serverEndpoint);
client.Linger = 0;
client.Linger = TimeSpan.Zero;
client.PollInHandler += PollInHandler;

return client;
Expand Down Expand Up @@ -75,9 +75,9 @@ public static void Main(string[] args)
}
}

private static void PollInHandler(ZmqSocket ZmqSocket, Poller revents)
private static void PollInHandler(ZmqSocket socket, Poller revents)
{
var reply = ZmqSocket.Receive(Encoding.Unicode);
var reply = socket.Receive(Encoding.Unicode);

if (Int32.Parse(reply) == sequence)
{
Expand Down
6 changes: 3 additions & 3 deletions examples/C#/lpserver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Lazy Pirate server
// Binds REQ ZmqSocket to tcp://*:5555
// Binds REQ socket to tcp://*:5555
// Like hwserver except:
// echoes request as-is
// randomly runs slowly, or exits to simulate a crash.
Expand All @@ -13,9 +13,9 @@
using System.Threading;
using ZeroMQ;

namespace ZMQGuide
namespace zguide.lpserver
{
internal class Program31
internal class Program
{
public static void Main(string[] args)
{
Expand Down
Loading

0 comments on commit 61f0831

Please sign in to comment.