public WriteLine ( string text ) : SignalFuture | ||
text | string | |
return | SignalFuture |
static IEnumerator<object> SendTask (SocketDataAdapter adapter) { var output = new AsyncTextWriter(adapter, Encoding.ASCII); output.AutoFlush = true; Writer = output; string nextMessageText = String.Format("ChatBot{0:00000}", Process.GetCurrentProcess().Id); Console.Title = nextMessageText; int i = 0; yield return new Sleep(new Random(Process.GetCurrentProcess().Id).NextDouble()); while (true) { var f = output.WriteLine(nextMessageText); yield return f; if (f.Failed) { Disconnected = true; throw new DisconnectedException(); } i += 1; if ((i % 1000) == 0) Console.WriteLine("Sent: {0}", i); nextMessageText = String.Format("Message {0}", i); yield return new Sleep(SendRate); } }
public void WriteLineTest() { var f = Writer.WriteLine("test"); f.GetCompletionEvent().Wait(); f = Writer.WriteLine("foo"); f.GetCompletionEvent().Wait(); Assert.AreEqual(String.Empty, GetTestDataString()); f = Writer.Flush(); f.GetCompletionEvent().Wait(); Assert.AreEqual("test\r\nfoo\r\n", GetTestDataString()); }
private IEnumerator<object> SendHeadersTask() { const int writeBufferSize = 1024; using (var atw = new AsyncTextWriter(Adapter, Encoding.ASCII, writeBufferSize, false)) { var prologue = String.Format( "HTTP/1.1 {0} {1}", StatusCode, StatusText ?? (StatusCode == 200 ? "OK" : "Unknown") ); yield return atw.WriteLine(prologue); foreach (var header in Headers) yield return atw.WriteLine(header.ToString()); yield return atw.WriteLine(""); yield return atw.Flush(); } }
static IEnumerator<object> PeerTask (TcpClient client, Peer peer) { var adapter = new SocketDataAdapter(client.Client, true); var input = new AsyncTextReader(adapter, Encoding.ASCII); var output = new AsyncTextWriter(adapter, Encoding.ASCII); adapter.ThrowOnDisconnect = false; adapter.ThrowOnFullSendBuffer = false; output.AutoFlush = true; peer.Input = input; peer.Output = output; yield return output.WriteLine("Welcome! Please enter your name."); string name = null; yield return input.ReadLine().Bind(() => name); if (name == null) { PeerDisconnected(peer); yield break; } peer.Name = name; PeerConnected(peer); yield return output.Write(VT100.EraseScreen); string nextLine = null; while (peer.Connected) { var f = input.ReadLine(); yield return f; if (!f.GetResult(out nextLine) || nextLine == null) { PeerDisconnected(peer); yield break; } if (nextLine.Length > 0) DispatchNewMessage(peer, nextLine); } }