static void Main(string[] args) { TcpClientSession clientSession= new AsyncTcpSession(new DnsEndPoint("127.0.0.1", 55555)); clientSession.Connect(); clientSession.Connected += ClientSession_Connected; clientSession.Closed += ClientSession_Closed; clientSession.Error += ClientSession_Error; clientSession.DataReceived += ClientSession_DataReceived; while (true) { if (clientSession.IsConnected) { break; } Thread.Sleep(1000); } var data=BlockWriter.GetBytes("abcdefg"); while (true) { clientSession.Send(data, 0, data.Length); Interlocked.Increment(ref _sendedBlockCount); } Console.ReadKey(); }
public static void sendMessage(AsyncTcpSession client, BasePacket packet) { // using (MemoryStream sendStream = new MemoryStream()) { // CodedOutputStream os = CodedOutputStream.CreateInstance(sendStream); // WriteMessageNoTag equivalent to WriteVarint32, WriteByte (byte []) // that is: variable length message header + message body // os.WriteMessageNoTag(request); // os.WriteRawBytes(bytes); // os.Flush(); MemoryStream sendStream = new MemoryStream(); packet.WriteTo(sendStream); byte[] bytes = sendStream.ToArray(); client.Send(new ArraySegment<byte>(bytes)); // } }