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(); }
void client_DataReceived(EventDrivenTCPClient sender, object data) { string msgs = data as string; foreach (string msg in msgs.Split(';')) if (msg.Length > 0) HandleMessage(msg); }
private void client_DataReceived(EventDrivenTCPClient sender, object data) { var msgs = (string)data; foreach (var msg in msgs.Split(';')) { if (msg.Length > 0) { HandleMessage(msg); } } }
void client_DataReceived(EventDrivenTCPClient sender, object data) { string msgs = data as string; foreach (string msg in msgs.Split(';')) { if (msg.Length > 0) { HandleMessage(msg); } } }
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(); } } }
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(); } } }
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(); }