private void ReleaseSock() { m_stop = true; if (m_morze != null) { if (m_morze != null) { try { Monitor.Enter(m_morze); m_morze.Close(); } finally { Monitor.Exit(m_morze); m_netStream.Dispose(); m_netStream = null; m_morze = null; } } } if (m_sync != null) { try { IDisposable d; Monitor.Enter(m_sync); d = m_sync as IDisposable; if (d != null) { d.Dispose(); } } finally { Monitor.Exit(m_sync); m_sync = null; } } }
public SMSSync SetAsync(MORZESendAsync async, byte[] hellosign) { byte [] syncKey = async.Decrypt(m_Data); byte[] t; byte algo = syncKey[0]; SMSSync sync = null; switch (algo) { case 1: //DES t = new byte[syncKey.Length - 1]; Array.Copy(syncKey, 1, t, 0, t.Length); sync = new SMSDES(t, hellosign); m_Sync = sync; break; default: throw new Exception(string.Format("Неподдреживаемый алгоритм симметричного шифрования - {0}", algo.ToString())); } return(sync); }
private void thRecvCommand() { MORZERecvCommand rcmd; MORZECommand cmd; try { do { rcmd = new MORZERecvCommand(m_account, m_netStream); cmd = rcmd.recvCmd(); if (cmd != null) { SMSRecvHello rcvhl = null; if (rcvhl == null && cmd is SMSRecvHello == true) { rcvhl = cmd as SMSRecvHello; if (rcvhl.isValid(m_helloSign) == true) { OnConnectChange(true, string.Empty); } else { OnConnectChange(false, string.Empty); } } //else if (rcvhl == null && cmd is SMSRecvHello == false) // OnConnectChange(false , "Неверный ответ сервера"); } if (cmd != null && cmd is MORZERecvSynKey == true) { MORZERecvSynKey srvSync = cmd as MORZERecvSynKey; srvSync.SetAsync(m_sendAsyngCmd, m_helloSign); m_sendAsyngCmd.Dispose(); m_sendAsyngCmd = null; m_sync = srvSync.SyncCryptor; if (OnConnected != null) { OnConnected(); } } if (cmd != null && cmd is MORZERecvMessages == true) {//принято сообщение MORZERecvMessages rm = cmd as MORZERecvMessages; if (rm.isResponses == true) {//есть ответные сообщения List <SMSSendCommand> res = rm.Responses; foreach (SMSSendCommand cm in res) { SMSSendExt setext = cm as SMSSendExt; if (setext != null) { setext.SMSNet = this; } cm.Send(m_netStream); } } } } while (m_stop == false); } catch (Exception exp) { if (m_stop == false) { OnConnectChange(false, exp.Message); } } }