private void btnStart_Click(object sender, EventArgs e) { try { String ip = this.txtIpAddress.Text.Trim(); ushort port = ushort.Parse(this.txtPort.Text.Trim()); // 写在这个位置是上面可能会异常 SetAppState(AppState.Starting); server.IpAddress = ip; server.Port = port; // 启动服务 if (server.Start()) { this.Text = string.Format("{2} - ({0}:{1})", ip, port, title); SetAppState(AppState.Started); AddMsg(string.Format("$Server Start OK -> ({0}:{1})", ip, port)); } else { SetAppState(AppState.Stoped); throw new Exception(string.Format("$Server Start Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); } } catch (Exception ex) { AddMsg(ex.Message); } }
private void buttonStart_Click(object sender, EventArgs e) { try { string ip = textBoxIPAdress.Text.Trim(); ushort port = ushort.Parse(textBoxPort.Text.Trim()); appState = AppState.Starting; server.IpAddress = ip; server.Port = port; if (server.Start()) { appState = AppState.Started; SetControlState(); } else { appState = AppState.Stoped; SetControlState(); throw new Exception(string.Format("服务端启动失败:{0},{1}", server.ErrorMessage, server.ErrorCode)); } } catch (Exception exc) { ShowMSG(exc.Message); } }
private Boolean ServiceStart() { try { SetAppState(AppState.Starting); server.IpAddress = "0.0.0.0"; server.Port = (ushort)(serviceConfig.ServicePort); // 启动服务 if (server.Start()) { SetAppState(AppState.Started); AddMsg(string.Format("$Server Start OK -> ({0}:{1})", server.IpAddress, server.Port)); } else { SetAppState(AppState.Stoped); throw new Exception(string.Format("$Server Start Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); } return(false); } catch (Exception ex) { AddMsg(ex.Message); return(false); } }
public bool Start(String sIp, ushort nPort) { this.m_sIP = sIp; this.m_nPort = nPort; m_tcpserver.IpAddress = sIp; m_tcpserver.Port = (ushort)nPort; m_tcpserver.OnPrepareListen += new TcpServerEvent.OnPrepareListenEventHandler(OnPrepareListen); m_tcpserver.OnAccept += new HPSocketCS.TcpServerEvent.OnAcceptEventHandler(OnAccept); m_tcpserver.OnSend += new TcpServerEvent.OnSendEventHandler(OnSend); m_tcpserver.OnPointerDataReceive += new TcpServerEvent.OnPointerDataReceiveEventHandler(OnPointerDataReceive); m_tcpserver.OnClose += new TcpServerEvent.OnCloseEventHandler(OnClose); m_tcpserver.OnShutdown += new TcpServerEvent.OnShutdownEventHandler(OnShutdown); if (!m_tcpserver.Start()) { Log.WriteLog(Log.LOGTYPE.ERROR, "start tcpserver error!" + sIp + " port:" + nPort.ToString()); return(false); } return(true); }
private void StartServer() { server.IpAddress = ip; server.Port = port; server.SocketBufferSize = 102400; //初始化这个服务器的所有dtu dtuDic = DTUUtil.getInstance().getDTUDic(); // 启动服务 if (server.Start()) { string text = string.Format("{2} - ({0}:{1})", ip, port, desc); if (OnMessage != null) { OnMessage(text); } isShutDown = false; } else { throw new Exception(string.Format("$Server Start Error -> {0}({1})", server.ErrorMessage, server.ErrorCode)); } }