using System; using System.Collections.Generic; using System.Text; namespace POSCorePrint { /// /// 打印机 /// internal class Content { /// /// ID /// public string ID { get; set; } /// /// 打印的内容 /// public string ContentVal { get; set; } /// /// 通过Socket方式判断打印机是否正常连接 /// /// /// /// //internal static bool IsConnect(string ip, int port) //{ // //Task.Delay(10); // var isConnect = false; // IPAddress iPAddress = IPAddress.Parse(ip); // IPEndPoint iPEndPoint = new IPEndPoint(iPAddress, port); // Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // try // { // IAsyncResult asyncResult = socket.BeginConnect(iPEndPoint, null, null); // asyncResult.AsyncWaitHandle.WaitOne(2000, true); // if (asyncResult.IsCompleted) // isConnect = true; // LogHelper.Log().Warn($"打印机 {ip}" + (isConnect ? "正常" : "离线!")); // } // catch (Exception ex) // { // ILog log = LogHelper.Log(); // Console.WriteLine($" {ip} 判断打印机是否正常连接失败:【{ex.Message}】",ex); // } // finally // { // socket.Close(); // } // return isConnect; //} } }