public bool ConnectServer(String srvIP, UInt32 srvPort, UInt32 waitPort, CMD_CALLBACK_PROC pfnCmdProc, object pParam) { if (srvIP.Length == 0) { return(false); } connectFlag = false; cmdProc = pfnCmdProc; cmdParam = pParam; StartTCPServer(waitPort); cmd.SetSendMode(true); cmd.SetNWSetting(srvIP, srvPort); if (cmd.SendRegistTCP(waitPort) != 1) { return(false); } else { connectFlag = true; connectedIP = srvIP; connectedPort = srvPort; return(true); } }
public bool StartServer(string strEventName, string strPipeName, CMD_CALLBACK_PROC pfnCmdProc, object pParam, ThreadPriority iThreadPriority, int iCtrlCmdEventID) { if (pfnCmdProc == null || strEventName.Length == 0 || strPipeName.Length == 0) { return(false); } if (m_ServerThread != null) { return(false); } PipeServerThread RunThread = new PipeServerThread(m_hStopEvent); RunThread.m_pCmdProc = pfnCmdProc; RunThread.m_pParam = pParam; RunThread.m_strEventName = strEventName; RunThread.m_strPipeName = strPipeName; RunThread.m_iCtrlCmdEventID = iCtrlCmdEventID; CommonUtil._ResetEvent(m_hStopEvent); m_ServerThread = new Thread(new ThreadStart(RunThread.Run)); m_ServerThread.Priority = iThreadPriority; m_ServerThread.Start(); return(true); }
public bool StartServer(string strEventName, string strPipeName, CMD_CALLBACK_PROC pfnCmdProc, object pParam, ThreadPriority iThreadPriority, int iCtrlCmdEventID) { if (pfnCmdProc == null || strEventName.Length == 0 || strPipeName.Length == 0) { return false; } if (m_ServerThread != null) { return false; } PipeServerThread RunThread = new PipeServerThread(m_hStopEvent); RunThread.m_pCmdProc = pfnCmdProc; RunThread.m_pParam = pParam; RunThread.m_strEventName = strEventName; RunThread.m_strPipeName = strPipeName; RunThread.m_iCtrlCmdEventID = iCtrlCmdEventID; CommonUtil._ResetEvent(m_hStopEvent); m_ServerThread = new Thread(new ThreadStart(RunThread.Run)); m_ServerThread.Priority = iThreadPriority; m_ServerThread.Start(); return true; }
public bool ConnectServer(String srvIP, UInt32 srvPort, UInt32 waitPort, CMD_CALLBACK_PROC pfnCmdProc, object pParam) { if (srvIP.Length == 0) { return(false); } connectFlag = false; cmdProc = pfnCmdProc; cmdParam = pParam; StartTCPServer(waitPort); cmd.SetSendMode(true); String wIPAddress = srvIP; IPAddress[] IpAddress = Dns.GetHostAddresses(srvIP); foreach (IPAddress wIP in IpAddress) { if (!wIP.IsIPv6LinkLocal) { wIPAddress = wIP.ToString(); break; } } cmd.SetNWSetting(wIPAddress, srvPort); //cmd.SetNWSetting(srvIP, srvPort); if (cmd.SendRegistTCP(waitPort) != 1) { return(false); } else { connectFlag = true; connectedIP = srvIP; connectedPort = srvPort; return(true); } }
public bool ConnectServer(String srvIP, UInt32 srvPort, UInt32 waitPort, CMD_CALLBACK_PROC pfnCmdProc, object pParam) { if (srvIP.Length == 0) { return false; } connectFlag = false; cmdProc = pfnCmdProc; cmdParam = pParam; StartTCPServer(waitPort); cmd.SetSendMode(true); String wIPAddress = srvIP; IPAddress[] IpAddress = Dns.GetHostAddresses(srvIP); foreach (IPAddress wIP in IpAddress) { if (!wIP.IsIPv6LinkLocal) { wIPAddress = wIP.ToString(); break; } } cmd.SetNWSetting(wIPAddress, srvPort); //cmd.SetNWSetting(srvIP, srvPort); if (cmd.SendRegistTCP(waitPort) != 1) { return false; } else { connectFlag = true; connectedIP = srvIP; connectedPort = srvPort; return true; } }
public bool StartServer(string strEventName, string strPipeName, CMD_CALLBACK_PROC pfnCmdProc, object pParam) { return StartServer(strEventName, strPipeName, pfnCmdProc, pParam, ThreadPriority.Normal, -1); }
public bool StartServer(string strEventName, string strPipeName, CMD_CALLBACK_PROC pfnCmdProc, object pParam) { return(StartServer(strEventName, strPipeName, pfnCmdProc, pParam, ThreadPriority.Normal, -1)); }
public bool ConnectServer(string srvIP, uint srvPort, uint waitPort, CMD_CALLBACK_PROC pfnCmdProc, object pParam) { if (srvIP.Length == 0) { return false; } connectFlag = false; cmdProc = pfnCmdProc; cmdParam = pParam; if (!StartTCPServer(waitPort)) return false; cmd.SetConnectTimeOut(500); cmd.SetSendMode(true); cmd.SetNWSetting(srvIP, srvPort); if (cmd.SendRegistTCP(waitPort) == (uint)ErrCode.CMD_SUCCESS) { connectFlag = true; connectedIP = srvIP; connectedPort = srvPort; callbackPort = waitPort; return true; } return false; }
public bool StartServer(string strEventName, string strPipeName, CMD_CALLBACK_PROC pfnCmdProc, object pParam) { if (pfnCmdProc == null || strEventName.Length == 0 || strPipeName.Length == 0) { return(false); } if (m_ServerThread != null) { return(false); } m_StopFlag = false; m_PulseEvent = new AutoResetEvent(false); m_ServerThread = new Thread(new ThreadStart(() => { using (EventWaitHandle eventConnect = new EventWaitHandle(false, EventResetMode.AutoReset, strEventName)) using (NamedPipeServerStream pipe = new NamedPipeServerStream( strPipeName.Substring(strPipeName.StartsWith("\\\\.\\pipe\\", StringComparison.OrdinalIgnoreCase) ? 9 : 0), PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) { while (m_StopFlag == false) { pipe.BeginWaitForConnection(asyncResult => { try { pipe.EndWaitForConnection(asyncResult); m_PulseEvent.Set(); } catch (ObjectDisposedException) { } }, null); eventConnect.Set(); m_PulseEvent.WaitOne(); if (pipe.IsConnected) { byte[] bHead = new byte[8]; if (pipe.Read(bHead, 0, 8) == 8) { CMD_STREAM stCmd = new CMD_STREAM(); stCmd.uiParam = BitConverter.ToUInt32(bHead, 0); stCmd.uiSize = BitConverter.ToUInt32(bHead, 4); stCmd.bData = stCmd.uiSize == 0 ? null : new byte[stCmd.uiSize]; if (stCmd.uiSize == 0 || pipe.Read(stCmd.bData, 0, stCmd.bData.Length) == stCmd.bData.Length) { CMD_STREAM stRes = new CMD_STREAM(); pfnCmdProc.Invoke(pParam, stCmd, ref stRes); if (stRes.uiParam == (uint)ErrCode.CMD_NEXT) { // Emun用の繰り返しは対応しない throw new InvalidOperationException(); } else if (stRes.uiParam != (uint)ErrCode.CMD_NO_RES) { BitConverter.GetBytes(stRes.uiParam).CopyTo(bHead, 0); BitConverter.GetBytes(stRes.uiSize).CopyTo(bHead, 4); pipe.Write(bHead, 0, 8); if (stRes.uiSize != 0 && stRes.bData != null && stRes.bData.Length >= stRes.uiSize) { pipe.Write(stRes.bData, 0, (int)stRes.uiSize); } } } } pipe.WaitForPipeDrain(); pipe.Disconnect(); } } } })); m_ServerThread.Start(); return(true); }