예제 #1
0
        public DraftClient(DraftWindow draftWindow, string hostname, string alias)
        {
            this.draftWindow = draftWindow;
            this.alias       = alias;

            if (!IPAddress.TryParse(hostname, out var address))
            {
                IPHostEntry hostEntry = Dns.GetHostEntry(hostname);
                if (hostEntry.AddressList.Length == 0)
                {
                    draftWindow.PrintLine("Couldn't resolve hostname!");
                    return;
                }
                address = hostEntry.AddressList[0];
            }

            client = new EventDrivenTCPClient(address, Util.PORT, false)
            {
                DataEncoding = Encoding.UTF8
            };
            client.ConnectionStatusChanged += client_ConnectionStatusChanged;
            client.DataReceived            += client_DataReceived;

            client.Connect();
        }
예제 #2
0
 void client_DataReceived(EventDrivenTCPClient sender, object data)
 {
     string msgs = data as string;
     foreach (string msg in msgs.Split(';'))
         if (msg.Length > 0)
             HandleMessage(msg);
 }
예제 #3
0
        private void client_DataReceived(EventDrivenTCPClient sender, object data)
        {
            var msgs = (string)data;

            foreach (var msg in msgs.Split(';'))
            {
                if (msg.Length > 0)
                {
                    HandleMessage(msg);
                }
            }
        }
예제 #4
0
        void client_DataReceived(EventDrivenTCPClient sender, object data)
        {
            string msgs = data as string;

            foreach (string msg in msgs.Split(';'))
            {
                if (msg.Length > 0)
                {
                    HandleMessage(msg);
                }
            }
        }
예제 #5
0
 void client_ConnectionStatusChanged(EventDrivenTCPClient sender, EventDrivenTCPClient.ConnectionStatus status)
 {
     if (status == EventDrivenTCPClient.ConnectionStatus.Connecting)
         draftWindow.PrintLine("Connecting...");
     else if (status == EventDrivenTCPClient.ConnectionStatus.DisconnectedByHost || status == EventDrivenTCPClient.ConnectionStatus.DisconnectedByUser)
     {
         draftWindow.PrintLine("Connection failed: " + status.ToString());
         if (!draftDone)
         {
             draftWindow.Invoke(new MethodInvoker(delegate
             {
                 draftWindow.ClearDraftPicker();
                 draftWindow.OpenConnectWindow();
             }));
             draftWindow.ClearCardPool();
         }
     }
 }
예제 #6
0
 private void client_ConnectionStatusChanged(EventDrivenTCPClient sender, EventDrivenTCPClient.ConnectionStatus status)
 {
     if (status == EventDrivenTCPClient.ConnectionStatus.Connecting)
     {
         draftWindow.PrintLine("Connecting...");
     }
     else if (status == EventDrivenTCPClient.ConnectionStatus.DisconnectedByHost || status == EventDrivenTCPClient.ConnectionStatus.DisconnectedByUser)
     {
         draftWindow.PrintLine($"Connection failed: {status}");
         if (!draftDone)
         {
             draftWindow.Invoke(new MethodInvoker(delegate
             {
                 draftWindow.ClearDraftPicker();
                 draftWindow.OpenConnectWindow();
             }));
             draftWindow.ClearCardPool();
         }
     }
 }
예제 #7
0
        public DraftClient(DraftWindow draftWindow, string hostname, string alias)
        {
            this.draftWindow = draftWindow;
            this.alias = alias;

            IPAddress address;
            if (!IPAddress.TryParse(hostname, out address))
            {
                IPHostEntry hostEntry = Dns.GetHostEntry(hostname);
                if (hostEntry.AddressList.Length == 0)
                {
                    draftWindow.PrintLine("Couldn't resolve hostname!");
                    return;
                }
                address = hostEntry.AddressList[0];
            }
            client = new EventDrivenTCPClient(address, 10024, false);
            client.DataEncoding = Encoding.UTF8;
            client.ConnectionStatusChanged += new EventDrivenTCPClient.delConnectionStatusChanged(client_ConnectionStatusChanged);
            client.DataReceived += new EventDrivenTCPClient.delDataReceived(client_DataReceived);

            client.Connect();
        }