本文整理汇总了C#中ZmqSocket.Send方法的典型用法代码示例。如果您正苦于以下问题:C# ZmqSocket.Send方法的具体用法?C# ZmqSocket.Send怎么用?C# ZmqSocket.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZmqSocket
的用法示例。
在下文中一共展示了ZmqSocket.Send方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
public void Send(ZmqSocket socket)
{
for (int index = frames.Count - 1; index > 0; index--)
{
socket.SendMore(frames[index]);
}
socket.Send(frames[0]);
}
示例2: proxy
private void proxy(ZmqSocket from, ZmqSocket to)
{
var buffer = new byte[2048];
while (true)
{
var count = from.Receive(buffer);
Console.WriteLine("proxying");
if (from.ReceiveMore)
to.Send(buffer, count, SocketFlags.SendMore);
else
{
to.Send(buffer, count, SocketFlags.None);
break;
}
}
}
示例3: ReceiverPollInHandler
private static void ReceiverPollInHandler(ZmqSocket receiver, ZmqSocket sender)
{
string task = receiver.Receive(Encoding.Unicode);
// Simple progress indicator for the viewer;
Console.WriteLine("{0}.", task);
int sleepTime = Convert.ToInt32(task);
Thread.Sleep(sleepTime);
// Send 'result' to the sink
sender.Send("", Encoding.Unicode);
}
示例4: RelayMessage
private static void RelayMessage(ZmqSocket source, ZmqSocket destination)
{
bool hasMore = true;
while (hasMore)
{
// side effect warning!
// note! that this uses Receive mode that gets a byte[], the router c# implementation
// doesnt work if you get a string message instead of the byte[] i would prefer the solution thats commented.
// but the router doesnt seem to be able to handle the response back to the client
//string message = source.Receive(Encoding.Unicode);
//hasMore = source.RcvMore;
//destination.Send(message, Encoding.Unicode, hasMore ? SendRecvOpt.SNDMORE : SendRecvOpt.NONE);
byte[] message = new byte[0];
source.Receive(message);
hasMore = source.ReceiveMore;
destination.Send(message, message.Length, hasMore ? SocketFlags.SendMore : SocketFlags.None);
}
}
示例5: Main
static void Main(string[] args)
{
context_ = ZmqContext.Create();
socket_ = context_.CreateSocket(SocketType.PUB);
socket_.Bind("tcp://127.0.0.1:5000");
bool publish = true;
Task.Run(() => {
while (publish)
{
string timestring = DateTime.Now.ToString("u");
Console.WriteLine("Sending '{0}' to subscribers", timestring);
socket_.Send(timestring, Encoding.Unicode);
Thread.Sleep(1000);
}
});
Console.ReadLine();
publish = false;
}
示例6: relay
private void relay(ZmqSocket source, ZmqSocket destination)
{
bool hasMore = true;
while (hasMore)
{
// no buffer overflow safety here, need to add that
var number = source.Receive(_buffer);
hasMore = source.ReceiveMore;
if (hasMore)
{
destination.SendMore(_buffer.Take(number).ToArray());
}
else
{
destination.Send(_buffer.Take(number).ToArray());
}
}
}
示例7: ClientThread
private void ClientThread()
{
try
{
status = 1;
context = ZmqContext.Create();
socket = context.CreateSocket(SocketType.DEALER);
window.SetProgress(5);
window.SetStatus("Contacting server...");
window.Log("Attempting connection to server...");
window.Log(" --> " + Settings.Default.ServerAddress);
bool connected = false;
{
byte[] identity = new byte[15];
new Random().NextBytes(identity);
socket.Identity = identity;
var helloMessage = new[] { (byte)MessageIdentifier.Init };
int attempt = 1;
var endpoint = Settings.Default.ServerAddress;
socket.Connect(endpoint);
socket.Send(helloMessage);
while (!connected)
{
var message = socket.ReceiveMessage(TimeSpan.FromSeconds(5));
if (message.TotalSize == 0)
{
window.Log("(" + attempt + ") Failed to connect, trying again in 5 seconds...");
}
else
{
window.Log("Received response, verifying...");
//check command value
if (message.First.Buffer[0] == (byte)MessageIdentifier.SetIdentity)
{
assignedIdentity = message.First.Buffer.Skip(1).ToArray();
window.Log("Received a new " + assignedIdentity.Length + " byte identity.");
socket.Identity = assignedIdentity;
socket.Disconnect(endpoint);
var finalSocket = context.CreateSocket(SocketType.DEALER);
socket.Dispose();
socket = finalSocket;
socket.Identity = assignedIdentity;
socket.TcpKeepalive = TcpKeepaliveBehaviour.Enable;
socket.Connect(endpoint);
socket.Send(new byte[] { (byte)MessageIdentifier.SetIdentity });
break;
}
if (message.First.Buffer[0] == (byte)MessageIdentifier.InvalidIdentity)
{
window.Log("Server responded with invalid identity. Trying again.");
}
}
attempt++;
Thread.Sleep(5000);
}
window.Log("Connected to master server after " + attempt + " attempts.");
window.SetProgress(20);
window.SetStatus("Synchronizing encryption...");
}
//We are connected!
window.Log("Waiting for encryption sequence...");
ZmqMessage msg = socket.ReceiveMessage();
if (msg.First.Buffer[0] != (byte)MessageIdentifier.BeginEncryption)
{
LogUnexpectedMessage(msg.First.Buffer);
window.Log("Crucial unexpected result, disconnecting.");
socket.Send(new byte[] { (byte)MessageIdentifier.Disconnect });
status = 0;
socket.Dispose();
context.Dispose();
return;
}
window.Log("Sending encryption key...");
byte[] encryptMsg = new byte[1 + keyHash.Length];
encryptMsg[0] = (byte)MessageIdentifier.BeginEncryption;
keyHash.CopyTo(encryptMsg, 1);
socket.Send(encryptMsg);
window.Log("Waiting for response...");
msg = socket.ReceiveMessage();
if (msg.First.Buffer[0] != (byte)MessageIdentifier.ConfirmEncryption)
{
window.Log("Invalid encryption key. Exiting...");
status = 0;
socket.Send(BuildMessage(MessageIdentifier.Disconnect, null, false));
return;
}
string salt = Encoding.UTF8.GetString(DecryptMessage(msg.First.Buffer.Skip(1).ToArray()));
heartbeat.Start();
window.Log("Connected, encrypted, beginning login.");
window.SetStatus("Logging in...");
//.........这里部分代码省略.........
示例8: AcceptDataAdditionRequest
/// <summary>
/// Handles incoming data "push" requests: the client sends data for us to add to local storage.
/// </summary>
private void AcceptDataAdditionRequest(string requesterIdentity, ZmqSocket socket)
{
//final message part: receive the DataAdditionRequest object
int size;
var ms = new MemoryStream();
byte[] buffer = socket.Receive(null, TimeSpan.FromMilliseconds(10), out size);
if (size <= 0) return;
var request = MyUtils.ProtoBufDeserialize<DataAdditionRequest>(buffer, ms);
//log the request
Log(LogLevel.Info, string.Format("Received data push request for {0}.",
request.Instrument.Symbol));
//start building the reply
socket.SendMore(requesterIdentity, Encoding.UTF8);
socket.SendMore("PUSHREP", Encoding.UTF8);
try
{
_broker.AddData(request);
socket.Send("OK", Encoding.UTF8);
}
catch (Exception ex)
{
socket.SendMore("ERROR", Encoding.UTF8);
socket.Send(ex.Message, Encoding.UTF8);
}
}
示例9: AcceptAvailableDataRequest
/// <summary>
/// Handles requests for information on data that is available in local storage
/// </summary>
private void AcceptAvailableDataRequest(string requesterIdentity, ZmqSocket socket)
{
//get the instrument
int size;
var ms = new MemoryStream();
byte[] buffer = socket.Receive(null, TimeSpan.FromMilliseconds(10), out size);
if (size <= 0) return;
var instrument = MyUtils.ProtoBufDeserialize<Instrument>(buffer, ms);
//log the request
Log(LogLevel.Info, string.Format("Received local data storage info request for {0}.",
instrument.Symbol));
//and send the reply
var storageInfo = _broker.GetAvailableDataInfo(instrument);
socket.SendMore(requesterIdentity, Encoding.UTF8);
socket.SendMore("AVAILABLEDATAREP", Encoding.UTF8);
socket.SendMore(MyUtils.ProtoBufSerialize(instrument, ms));
socket.SendMore(BitConverter.GetBytes(storageInfo.Count));
foreach (StoredDataInfo sdi in storageInfo)
{
socket.SendMore(MyUtils.ProtoBufSerialize(sdi, ms));
}
socket.Send("END", Encoding.UTF8);
}
示例10: RelayMessage
private void RelayMessage(ZmqSocket source, ZmqSocket destination)
{
try
{
var buffer = new byte[4096];
bool isProcessing = true;
while (_routing && isProcessing)
{
//int size = 0;
source.Receive(buffer);
if (IsStopCommand(Encoding.UTF8.GetString(buffer)))
{
_routing = false;
break;
}
else
{
if (source.ReceiveMore)
destination.SendMore(buffer);
//destination.SendMore(message, Encoding.UTF8);
else
destination.Send(buffer);
//destination.Send(message, Encoding.UTF8);
isProcessing = source.ReceiveMore;
}
}
}
catch (ZeroMQ.ZmqException ex)
{
Logger.Instance.Debug(ex);
}
}
示例11: RecieverPollInHandler
private void RecieverPollInHandler(ZmqSocket reciever, ZmqSocket sender)
{
Thread.Sleep(100);
var fileToMeasure = reciever.Receive(Encoding.Unicode);
Int64 fileLength = 0;
FileStream fs = null;
try
{
fs = File.OpenRead(fileToMeasure);
fileLength = fs.Length;
}
catch (IOException)
{
}
finally
{
if (fs != null) fs.Dispose();
}
Console.Write(".");
sender.Send(fileLength.ToString(), Encoding.Unicode);
}
示例12: Send
public void Send(ZmqSocket publisher)
{
publisher.SendMore(Key, Encoding.Unicode);
publisher.SendMore(BitConverter.GetBytes(Sequence));
publisher.Send(Body, Encoding.Unicode);
}
示例13: ContractServer
/// <summary>
/// The main loop. Runs on its own thread. Accepts requests on the REP socket, gets results from the InstrumentManager,
/// and sends them back right away.
/// </summary>
private void ContractServer()
{
var timeout = new TimeSpan(100000);
_socket = _context.CreateSocket(SocketType.REP);
_socket.Bind("tcp://*:" + _socketPort);
var ms = new MemoryStream();
List<Instrument> instruments;
while (_runServer)
{
string request = _socket.Receive(Encoding.UTF8, timeout);
if (request == null) continue;
//if the request is for a search, receive the instrument w/ the search parameters and pass it to the searcher
if (request == "SEARCH" && _socket.ReceiveMore)
{
int size;
byte[] buffer = _socket.Receive(null, timeout, out size);
var searchInstrument = MyUtils.ProtoBufDeserialize<Instrument>(buffer, ms);
Log(LogLevel.Info, string.Format("Instruments Server: Received search request: {0}",
searchInstrument));
try
{
instruments = _instrumentManager.FindInstruments(null, searchInstrument);
}
catch (Exception ex)
{
Log(LogLevel.Error, string.Format("Instruments Server: Instrument search error: {0}",
ex.Message));
instruments = new List<Instrument>();
}
}
else if (request == "ALL") //if the request is for all the instruments, we don't need to receive anything else
{
Log(LogLevel.Info, "Instruments Server: received request for list of all instruments.");
instruments = _instrumentManager.FindInstruments();
}
else if (request == "ADD") //request to add instrument
{
int size;
byte[] buffer = _socket.Receive(null, timeout, out size);
var instrument = MyUtils.ProtoBufDeserialize<Instrument>(buffer, ms);
bool addResult;
try
{
addResult = InstrumentManager.AddInstrument(instrument);
}
catch (Exception ex)
{
addResult = false;
Log(LogLevel.Error, string.Format("Instruments Server: Instrument addition error: {0}",
ex.Message));
}
_socket.Send(addResult ? "SUCCESS" : "FAILURE", Encoding.UTF8);
continue;
}
else //no request = loop again
{
continue;
}
byte[] uncompressed = MyUtils.ProtoBufSerialize(instruments, ms);//serialize the list of instruments
ms.Read(uncompressed, 0, (int)ms.Length); //get the uncompressed data
byte[] result = LZ4Codec.Encode(uncompressed, 0, (int)ms.Length); //compress it
//before we send the result we must send the length of the uncompressed array, because it's needed for decompression
_socket.SendMore(BitConverter.GetBytes(uncompressed.Length));
//then finally send the results
_socket.Send(result);
}
_socket.Dispose();
}