Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
    void OnGUI()
    {
        if (GUI.Button (new Rect(100, 130, 100, 25), "SuperSocket")) {
            buffer.Data = new byte[8192];
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(host), port);

            AsyncTcpSession client = new AsyncTcpSession(endPoint);
            client.Connected 	+= OnConnected;
            client.DataReceived += OnDataReceive;

            client.Connect();

            NamePacket.Builder b = new NamePacket.Builder();
            b.SetName("Client name data");
            NamePacket np = b.BuildPartial();

            MemoryStream stream = new MemoryStream();
            np.WriteTo(stream);
            byte[] bytes = stream.ToArray();

            BasePacket.Builder basePacketBuilder = new BasePacket.Builder();
            basePacketBuilder.SetPacketId(64553060);
            basePacketBuilder.SetPacketData(
                ByteString.CopyFrom(bytes)
            );

            BasePacket basePacket = basePacketBuilder.BuildPartial();

            sendMessage(client, basePacket);

            print("SuperSocket!");
        }
    }