public Int32 Connect(string sRemoteIP, Int32 iPrinterSN, Int32 iRemotePort = 17888) { int iErrCode = 0; iSN = iPrinterSN; if (tc == null) { tc = new TcpClient(); } byte[] inValue = new byte[] { 1, 0, 0, 0, 0x88, 0x13, 0, 0, 0xE8, 0x03, 0, 0 };// 首次探测时间5 秒, 间隔侦测时间1 秒 tc.Client.IOControl(IOControlCode.KeepAliveValues, inValue, null); try { tc.Connect(sRemoteIP, iRemotePort); ns = tc.GetStream(); } catch (SocketException se) { CLog.SaveException("---Tcp Connect---", se.Message); iErrCode = Constant.ERR_SOCKET_EXCEPTION; } catch (Exception e) { CLog.SaveException("---Tcp Connect---", e.Message); iErrCode = Constant.ERR_EXCEPTION; } if (tc.Connected) { return(Constant.ERR_OK); } else { return(Constant.ERR_ERROR); } }
private void btn_DelLine_Click(object sender, EventArgs e) { if (MainTables.SelectedIndex < 0) { return; } string sLineName = MainTables.TabPages[MainTables.SelectedIndex].Text; DialogResult rlt = MessageBox.Show("Are you sure delete this product-line[" + sLineName + "]?" , "", MessageBoxButtons.YesNo); if (rlt == DialogResult.No) { return; } MainTables.TabPages.Remove(MainTables.TabPages[MainTables.SelectedIndex]); LinePageForm lpf = getPage(sLineName); LineForms.Remove(lpf); if (MainTables.TabPages.Count == 0) { btn_DelLine.Enabled = false; btn_RenameLine.Enabled = false; } else { btn_DelLine.Enabled = true; btn_RenameLine.Enabled = true; } createAllLineName(); CLog.SaveLog("Delete line [" + sLineName + "]"); }
void ReciveMsg() { receiveEnd = false; while (true) { EndPoint point = new IPEndPoint(IPAddress.Any, 0);//用来保存发送方的ip和端口号 byte[] buffer = new byte[1024]; UdpSkt.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 13000); int length = 0; try { lock (UdpSkt) { length = UdpSkt.ReceiveFrom(buffer, ref point);//接收数据报 } } catch (SocketException e) { //超时 CLog.SaveException("---UDP Receive---", e.Message); break; } if (length > 0) { Int32 isn = buffer[4] + buffer[5] * 256 + buffer[6] * 256 * 256 + buffer[7] * 256 * 256 * 256; string IPPort = (point as IPEndPoint).ToString(); string[] strArray = IPPort.Split(new Char[] { ':' }); string strIP = strArray[0];//.Substring(1, strArray[0].Length - 2); lstFind.Add(strIP + "-" + isn.ToString()); //break; } } receiveEnd = true; }
private void frmMain_FormClosed(object sender, FormClosedEventArgs e) { //bCloseListen = true; CLog.SaveLog("-------------Close-----------"); }