Example #1
0
    public void SendText()
    {
        if (client == null)
        {
            client = new EasyClient();
            client.Initialize(new ProtoBufReceiveFilter(),
                              (msgWrapper) =>
            {
                var person = Person.Parser.ParseFrom(msgWrapper.Msg.Message);
                Debug.Log(person.Name);
                Debug.Log(person.Age);
            });
        }

        if (!client.IsConnected)
        {
            client.BeginConnect(new IPEndPoint(IPAddress.Parse(m_ServerIP), m_ServerPort));
            return;
        }

        Person newPerson = new Person {
            Name = m_PlayerName, Age = m_Age
        };

        m_MsgWrapper.Id      = 200;
        m_MsgWrapper.Message = newPerson.ToByteString();
        using (MemoryStream stream = new MemoryStream())
        {
            var os = new CodedOutputStream(stream);
            os.WriteBytes(m_MsgWrapper.ToByteString());
            os.Flush();
            var data = stream.ToArray();
            client.Send(data);
        }
    }
Example #2
0
        public override void Connect()
        {
            if (client.IsConnected)
            {
                return;
            }

            client.BeginConnect(endPoint);
        }
Example #3
0
 private void Form1_Load(object sender, EventArgs e)
 {
     client.BeginConnect(new IPEndPoint(IPAddress.Parse("192.168.137.22"), 2020));
     client.Initialize(new CallMessageFilter(), request =>
     {
     });
     if (client.IsConnected)
     {
         client.Send(GetBytes("CHECK:127.0.0.1\r\n"));
     }
 }
Example #4
0
 public void Init(IPEndPoint iep)
 {
     client = new EasyClient();
     client.Initialize(new MyReceiveFilter(), HandlePackage);
     //IPAddress ip = IPAddress.Parse("127.0.0.1");
     //client.BeginConnect(new IPEndPoint(ip, 7777));
     client.BeginConnect(iep);
     client.Connected += new System.EventHandler(client_Connected);
     client.Closed    += new System.EventHandler(client_Closed);
     client.Error     += new EventHandler <ErrorEventArgs>(client_Error);
 }
Example #5
0
    private void OnGUI()
    {
        if (GUILayout.Button("TCP Connect test"))
        {
            Debug.Log("Before network init at " + Time.realtimeSinceStartup);

            if (mClient == null)
            {
                mClient = new EasyClient();
                //mClient.Security.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Default;
                mClient.Closed    += MClient_Closed;
                mClient.Connected += MClient_Connected;
                mClient.Error     += MClient_Error;
            }
            // Initialize the client with the receive filter and request handler
            mClient.Initialize(new MyReceiveFilter(), MClient_Received);
            mClient.BeginConnect(new DnsEndPoint("172.17.99.3", 10009));

            Debug.Log("After network init at " + Time.realtimeSinceStartup);
        }
    }