コード例 #1
0
        public void ConnectRemoteClient(IPEndPoint ip)
        {
            T client_t = (T)Activator.CreateInstance(typeof(T), new object[] { true });
            T server_t = (T)Activator.CreateInstance(typeof(T), new object[] { false });

            client_t.FromByteHandler += ProtocolTreatmentExtension.FromBytes;
            server_t.FromByteHandler += ProtocolTreatmentExtension.FromBytes;

            client_t.FromContentHandler += ProtocolTreatmentExtension.FromContent;
            server_t.FromContentHandler += ProtocolTreatmentExtension.FromContent;

            client_t.OnMessageParsed += Client_t_OnMessageParsed;
            server_t.OnMessageParsed += Server_t_OnMessageParsed;

            CustomClient remoteClient = new CustomClient(ip);

            remoteClient.GetCustomInstanceId += RemoteClient_GetCustomInstanceId;
            remoteClient.OnCustomMessageSent += RemoteClient_OnCustomMessageSent;

            ProxyElement <T> proxy = new ProxyElement <T>()
            {
                LocalClient  = null,
                RemoteClient = remoteClient,

                ClientTreatment = client_t,
                ServerTreatment = server_t
            };

            Elements.Add(proxy);
        }
コード例 #2
0
 private void CustomProxy_OnClientDisconnected(CustomClient obj)
 {
     if (Elements.FirstOrDefault(x => x.LocalClient == obj) is ProxyElement <T> element)
     {
         Elements.Remove(element);
     }
 }
コード例 #3
0
 private void CustomProxy_OnClientConnected(CustomClient obj)
 {
     if (Elements.FirstOrDefault(x => x.LocalClient is null) is ProxyElement <T> proxy)
     {
         proxy.LocalClient = obj;
         proxy.Init();
     }
 }