void BtnTest_Click(object sender, RoutedEventArgs e) { try { if (mDecConnector != null) { mDecConnector.Close(); } mDecConnector = new DecConnector(); mDecConnector.Debug += msg => AppendMessage(string.Format("Connector\t{0}", msg)); mDecConnector.MessageReceivedEvent += DealMessageReceicedEvent; mDecConnector.Host = "192.168.6.27"; mDecConnector.Port = 3072; mDecConnector.ModuleType = 1101; mDecConnector.ModuleNumber = 0; mDecConnector.Connect(); if (!mDecConnector.IsConnected) { AppendMessage(string.Format("Connected fail.")); } } catch (Exception ex) { AppendMessage(ex.Message); } }
public void Close() { if (mDecConnector != null) { mDecConnector.Close(); mDecConnector = null; } }
void BtnConnect_Click(object sender, RoutedEventArgs e) { try { if (mDecConnector != null) { mDecConnector.Close(); } mDecConnector = new DecConnector(); mDecConnector.Debug += msg => AppendMessage(string.Format("Connector\t{0}", msg)); mDecConnector.MessageReceivedEvent += DealMessageReceicedEvent; mDecConnector.Host = "192.168.6.27"; mDecConnector.Port = 3072; mDecConnector.ModuleType = 0x1101; mDecConnector.ModuleNumber = 0; //订阅由VoiceServer相关的所有消息 MessageString mask = new MessageString(); mask.SourceModule = 0xffff; //模块掩码 mask.SourceNumber = 0x0000; mask.TargetModule = 0x0000; mask.TargetNumber = 0x0000; mask.LargeType = 0x0000; mask.MiddleType = 0x0000; mask.SmallType = 0x0000; mask.Number = 0x0000; MessageString message = new MessageString(); message.SourceModule = 0x1514; //由VoiceServer发布的所有消息 message.SourceNumber = 0x0000; message.TargetModule = 0x0000; message.TargetNumber = 0x0000; message.LargeType = 0x0000; message.MiddleType = 0x0000; message.SmallType = 0x0000; message.Number = 0x0000; mDecConnector.MaskMsg = mask; mDecConnector.MessageMsg = message; mDecConnector.Connect(); if (!mDecConnector.IsConnected) { AppendMessage(string.Format("Connected fail.")); } //mDecConnector.BeginConnect(); //启用了断线重连 } catch (Exception ex) { AppendMessage(ex.Message); } }
public OperationReturn PublishMessage(string content, MessageString message) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; bool bResult; try { if (mDecConnector == null || !mDecConnector.IsConnected) { mIsConnected = false; mDecConnector = new DecConnector(); mDecConnector.Debug += msg => OnDebug(LogMode.Debug, "DECConnector", msg); mDecConnector.MessageReceivedEvent += DecConnector_MessageReceivedEvent; mDecConnector.ServerConnectedEvent += DecConnector_ServerConnectedEvent; mDecConnector.AppName = string.Format("Wcf21061"); mDecConnector.Host = mHostAddress; mDecConnector.Port = mHostPort; mDecConnector.ModuleNumber = 0; mDecConnector.ModuleType = 2106; mDecConnector.DataEncrypt = 0; mDecConnector.DataFormat = DecDefines.NETPACK_BASEHEAD_VER1_FORMAT_XML; mResetEvent.Reset(); mDecConnector.Connect(); bResult = mResetEvent.WaitOne(mConnectTimeout * 1000); if (!bResult) { optReturn.Result = false; optReturn.Code = Defines.RET_TIMEOUT; optReturn.Message = string.Format("Connect timeout"); return(optReturn); } } if (!mIsConnected) { optReturn.Result = false; optReturn.Code = Defines.RET_NOT_CONNECTED; optReturn.Message = string.Format("Not connect to server"); return(optReturn); } //mResetEvent.Reset(); //mDecConnector.PublishMessage(content, message); //bResult = mResetEvent.WaitOne(mReceiveTimeout * 1000); //if (!bResult) //{ // optReturn.Result = false; // optReturn.Code = Defines.RET_TIMEOUT; // optReturn.Message = string.Format("Recieve timeout"); // return optReturn; //} mDecConnector.PublishMessage(content, message); Thread.Sleep(2000); //等待2s } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; optReturn.Exception = ex; } return(optReturn); }