本文整理汇总了C#中IoSession.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IoSession.Write方法的具体用法?C# IoSession.Write怎么用?C# IoSession.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IoSession
的用法示例。
在下文中一共展示了IoSession.Write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MessageReceived
/// <summary>
/// If the message is 'quit', we exit by closing the session. Otherwise,
/// we return the current date.
/// </summary>
public override void MessageReceived(IoSession session, Object message)
{
String str = message.ToString();
// "Quit" ? let's get out ...
if (str.Trim().Equals("quit", StringComparison.OrdinalIgnoreCase))
{
session.Close(true);
return;
}
// Send the current date back to the client
session.Write(DateTime.Now.ToString());
Console.WriteLine("Message written...");
}
示例2: MessageReceived
public override void MessageReceived(IoSession session, Object message)
{
Console.WriteLine("Player-" + id + ": RCVD " + message);
TennisBall ball = (TennisBall)message;
// Stroke: TTL decreases and PING/PONG state changes.
ball = ball.Stroke();
if (ball.TTL > 0)
{
// If the ball is still alive, pass it back to peer.
session.Write(ball);
}
else
{
// If the ball is dead, this player loses.
Console.WriteLine("Player-" + id + ": LOSE");
session.Close(true);
}
}
示例3: DoFlush
private void DoFlush(IoSession session, WriteOp op)
{
if (op != null && !op.IsExpired)
{
try
{
long cnt = flushCounter.AtomicIncrementAndGet();
long now = new DateTime().CurrentTimeMillis();
if (now - lastLogTime.ReadFullFence() > 60000)
{
lastLogTime.WriteFullFence(now);
string log = String.Format("opQueueSize: {0}, session: {1}, couner: {2}", opQueue.Count, session.RemoteEndPoint.ToString(), cnt);
client.Log.Info(log);
}
var writeFuture = session.Write(op.Command);
writeFuture.Complete += (s, e) =>
{
if (e.Future.Done)
{
flushing.AtomicExchange(false);
flushingOp.AtomicExchange(null);
}
else
{
if (!IsClosed)
{
Thread.Sleep(client.Config.EndpointSessionWriteRetryDealyInMills);
DoFlush(e.Future.Session, op);
}
}
};
}
catch (Exception ex)
{
client.Log.Error(ex);
flushing.AtomicExchange(false);
flushingOp.AtomicExchange(null);
}
}
else
{
flushing.AtomicExchange(false);
flushingOp.AtomicExchange(null);
}
}
示例4: Write
private void Write(IoSession session, String s)
{
session.Write(IoBuffer.Wrap(Encoding.ASCII.GetBytes(s)));
}
示例5: buttonConnect_Click
private void buttonConnect_Click(object sender, EventArgs e)
{
String server = textBoxServer.Text;
if (String.IsNullOrEmpty(server))
return;
if (checkBoxSSL.Checked)
{
if (!connector.FilterChain.Contains("ssl"))
connector.FilterChain.AddFirst("ssl", new SslFilter("TempCert", null));
}
else if (connector.FilterChain.Contains("ssl"))
{
connector.FilterChain.Remove("ssl");
}
IPEndPoint ep;
String[] parts = server.Trim().Split(':');
if (parts.Length > 0)
{
ep = new IPEndPoint(IPAddress.Parse(parts[0]), Int32.Parse(parts[1]));
}
else
{
ep = new IPEndPoint(IPAddress.Loopback, Int32.Parse(parts[0]));
}
IConnectFuture future = connector.Connect(ep).Await();
if (future.Connected)
{
session = future.Session;
session.Write("LOGIN " + textBoxUser.Text);
}
else
{
MessageBox.Show("Could not connect to " + server);
}
}
示例6: MessageReceived
public override void MessageReceived(IoSession session, Object message)
{
IoBuffer rb = message as IoBuffer;
if (rb == null)
return;
// Write the received data back to remote peer
IoBuffer wb = IoBuffer.Allocate(rb.Remaining);
wb.Put(rb);
wb.Flip();
session.Write(wb);
}