本文整理汇总了C#中Socket.Recv方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.Recv方法的具体用法?C# Socket.Recv怎么用?C# Socket.Recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Socket
的用法示例。
在下文中一共展示了Socket.Recv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Append
static void Append(Socket sock, string root)
{
var name = sock.Recv(Encoding.UTF8);
var fileName = Path.GetFileName(name) ?? "";
var combine = Path.Combine(root, fileName);
var s = new FileTapeStream(combine);
Console.WriteLine("Append {0}", fileName);
long result = 0;
while (true)
{
var verDat = sock.Recv();
if ((null == verDat) || (verDat.Length == 0))
break;
var version = BitConverter.ToInt64(verDat, 0);
var data = sock.Recv();
var cond = TapeAppendCondition.VersionIs(version);
result = s.TryAppend(data, cond);
if (result != 0)
Console.WriteLine(" " + result);
}
s.UpdateCounter(result);
sock.Send(BitConverter.GetBytes(result));
}
示例2: Recv
public static KvMsg Recv(Socket subscriber)
{
var key = subscriber.Recv(Encoding.Unicode);
var sequence = BitConverter.ToInt64(subscriber.Recv(), 0);
var body = subscriber.Recv(Encoding.Unicode);
return new KvMsg(sequence, key, body);
}
示例3: RecepcionHandShake
void RecepcionHandShake(Socket socket, IOMultiPlex revents)
{
var idcliente = socket.Recv();
socket.Send(nombreServidor);
MethodInvoker action=delegate { listanodos.Items.Add(Encoding.Unicode.GetString(idcliente));};
listanodos.BeginInvoke(action);
}
示例4: ReceiverPollInHandler
private static void ReceiverPollInHandler(Socket receiver, Socket sender)
{
var ms = receiver.Recv(Encoding.UTF8);
var timeout = TimeSpan.FromTicks(int.Parse(ms) * 10000L);
Console.WriteLine(ms);
Thread.Sleep(timeout);
sender.Send(string.Empty, Encoding.UTF8);
}
示例5: RecepcionDealer
static void RecepcionDealer(Socket socket, IOMultiPlex revents)
{
//Repetidor(socket,router );
var datos = socket.Recv();
string mensaje = string.Empty;
Guid identidad = new Guid(datos);
if (socket.RcvMore)
{
//delimitador vacio
socket.Recv();
mensaje = socket.Recv(Encoding.Unicode);
Console.WriteLine("Se recibio el mensaje en el dealer:" + mensaje);
}
router.SendMore(datos);
router.SendMore(string.Empty, Encoding.Unicode);
router.Send(mensaje, Encoding.Unicode);
}
示例6: FrontendPollInHandler
private void FrontendPollInHandler(Socket socket, IOMultiPlex revents)
{
// Process all parts of the message
bool isProcessing = true;
while (isProcessing) {
byte[] message = socket.Recv();
backend.Send(message, socket.RcvMore ? SendRecvOpt.SNDMORE : 0);
isProcessing = socket.RcvMore;
}
}
示例7: SendRequests
private static void SendRequests(Socket requester)
{
var message = Encoding.Unicode.GetBytes("Hello");
while (true)
{
requester.Send(message);
var response = requester.Recv();
Console.WriteLine("Response: {0}", Encoding.Unicode.GetString(response));
Thread.Sleep(1000);
}
}
示例8: Worker
private static void Worker()
{
using (Socket receiver = new Socket(SocketType.REP)) {
receiver.Connect("inproc://workers");
while (true) {
string message = receiver.Recv(Encoding.Unicode);
Thread.Sleep(1000);
receiver.Send(new Message("World"));
}
}
}
示例9: DoWork
private void DoWork(Socket consumer, Socket reporter, string workerId)
{
while (true)
{
var message = consumer.Recv();
ProcessWorkItem(message);
// Signal that we've finished the workitem.
reporter.Send(Encoding.Unicode.GetBytes(workerId));
}
}
示例10: HandleRequests
private static void HandleRequests(Socket responder)
{
while (true)
{
byte[] request = responder.Recv();
string message = Encoding.Unicode.GetString(request);
Console.WriteLine("Received: {0}", message);
responder.Send(Encoding.Unicode.GetBytes("World"));
}
}
示例11: Transmit
public static void Transmit()
{
using (var socket = new Socket(SocketType.REQ)) {
socket.Connect("tcp://localhost:5555");
const string request = "Hello";
for (int requestNbr = 0; requestNbr < 10; requestNbr++) {
Console.WriteLine("Sending request {0}...", requestNbr);
socket.Send(new Message(request));
var reply = socket.Recv<Message>();
Console.WriteLine("Received reply {0}: {1}", requestNbr, reply.Msg);
}
}
}
示例12: RecepcionRouter
static void RecepcionRouter(Socket socket, IOMultiPlex revents)
{
//Repetidor(socket, dealer);
var datos = socket.Recv();
Guid identidad = new Guid(datos);
if (socket.RcvMore)
{
// //delimitador vacio
socket.Recv();
var mensaje = socket.Recv(Encoding.Unicode);
Console.WriteLine("Se recibio el mensaje en el router:" + mensaje);
EnviarAWorker(identidad, mensaje);
}
}
示例13: Main
static void Main(string[] args)
{
using (var ar = new AsyncDevice("inproc://server", "inproc://asyncReturn", AsyncReturn))
using (Socket clientA = new Socket(SocketType.REQ), clientB = new Socket(SocketType.REQ)) {
ar.Start();
System.Threading.Thread.Sleep(1000);
clientA.Connect("inproc://server");
clientB.Connect("inproc://server");
clientA.Send("Hello from A", Encoding.Unicode);
clientB.Send("Hello from B", Encoding.Unicode);
Console.WriteLine(clientA.Recv(Encoding.Unicode));
Console.WriteLine(clientB.Recv(Encoding.Unicode));
Console.ReadLine();
}
}
示例14: RelayMessage
private static void RelayMessage(Socket source, Socket destination)
{
bool hasMore = true;
while (hasMore)
{
// side effect warning!
// note! that this uses Recv 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.Recv(Encoding.Unicode);
//hasMore = source.RcvMore;
//destination.Send(message, Encoding.Unicode, hasMore ? SendRecvOpt.SNDMORE : SendRecvOpt.NONE);
byte[] message = source.Recv();
hasMore = source.RcvMore;
destination.Send(message, hasMore ? SendRecvOpt.SNDMORE : SendRecvOpt.NONE);
}
}
示例15: Main
static void Main(string[] args)
{
Context contexto = new Context();
enviar= contexto.Socket(SocketType.REQ);
recibir = contexto.Socket(SocketType.REP);
Console.WriteLine("Cual es el nombre del cliente");
nombre=Console.ReadLine();
recibir.Identity = Encoding.Unicode.GetBytes(nombre);
enviar.Connect("tcp://127.0.0.1:5589");
recibir.Connect("tcp://127.0.0.1:5590");
enviar.Send(Encoding.Unicode.GetBytes(nombre));
servidor=enviar.Recv(Encoding.Unicode);
Console.WriteLine("Conectado");
items[0] = recibir.CreatePollItem(IOMultiPlex.POLLIN);
items[0].PollInHandler += new PollHandler(RecibirMensaje);
while (true)
{
contexto.Poll(items, -1);
}
Console.ReadKey();
enviar.Dispose();
}