private static TcpIpSession CreateTcpIpSession(SessionBindInfo bindInfo) { //Check that Host is not an empty string or null if (string.IsNullOrEmpty(bindInfo.ServerName)) { throw new InvalidOperationException("Host cannot be an empty string or null"); } //Check the port number is not set to an invalid value if (bindInfo.Port < IPEndPoint.MinPort || bindInfo.Port > IPEndPoint.MaxPort) { throw new InvalidOperationException( string.Format("Port must be set to a valid value between '{0}' and '{1}'", IPEndPoint.MinPort, IPEndPoint.MaxPort)); } IPAddress address = null; TcpIpSession session = null; if (!IPAddress.TryParse(bindInfo.ServerName, out address)) { session = TcpIpSession.OpenClientSession(bindInfo.ServerName, bindInfo.Port); } else { session = TcpIpSession.OpenClientSession(address, bindInfo.Port); } return(session); }
public static SmppClientSession Bind(SessionBindInfo bindInfo, int timeOut, SmppEncodingService smppEncodingService) { try { TcpIpSession tcpIpSession = null; if (bindInfo == null) { throw new ArgumentNullException("bindInfo"); } //-- tcpIpSession = CreateTcpIpSession(bindInfo); //-- SmppClientSession smppSession = new SmppClientSession(smppEncodingService); smppSession.vTcpIpSession = tcpIpSession; smppSession.ChangeState(SmppSessionState.Open); smppSession.AssembleComponents(); try { smppSession.BindSession(bindInfo, timeOut); } catch (Exception) { smppSession.DestroyTcpIpSession(); smppSession.DisassembleComponents(); throw; } return(smppSession); } catch (Exception ex) { _Log.ErrorFormat("200017:SMPP bind operation failed: {0}", ex, ex.Message); if (vTraceSwitch.TraceInfo) { string traceMessage = "200017:SMPP bind operation failed:"; if (ex is SmppException) { traceMessage += (ex as SmppException).ErrorCode.ToString() + " - "; } traceMessage += ex.Message; Trace.WriteLine(traceMessage); } throw; } }
private void BindSession(SessionBindInfo bindInfo, int timeOut) { _vTcpIpSession.SessionClosed += TcpIpSessionClosedEventHandler; BindRequest bindReq = bindInfo.CreatePdu(); _vTrans.Send(bindReq); BindResponse bindResp = null; try { bindResp = (BindResponse)_vRespHandler.WaitResponse(bindReq, timeOut); } catch (SmppResponseTimedOutException ex) { throw new SmppBindException(ex); } if (bindResp.Header.ErrorCode != 0) { throw new SmppBindException(bindResp.Header.ErrorCode); } //Copy settings _vSmscId = bindResp.SystemId; _vSystemId = bindInfo.SystemId; _vPassword = bindInfo.Password; _vAddressTon = bindInfo.AddressTon; _vAddressNpi = bindInfo.AddressNpi; //Start timer _vTimer.Start(); _vIsAlive = true; switch (bindReq.Header.CommandType) { case CommandType.BindTransceiver: ChangeState(SmppSessionState.Transceiver); break; case CommandType.BindReceiver: ChangeState(SmppSessionState.Receiver); break; case CommandType.BindTransmitter: ChangeState(SmppSessionState.Transmitter); break; } }
internal SessionBindInfo GetBindInfo() { SessionBindInfo bindInfo = new SessionBindInfo(); bindInfo.SystemID = vSystemID; bindInfo.Password = vPassword; bindInfo.ServerName = vHost; bindInfo.Port = vPort; bindInfo.InterfaceVersion = vInterfaceVersion; bindInfo.AddressTon = vAddressTon; bindInfo.AddressNpi = vAddressNpi; bindInfo.SystemType = vSystemType; return bindInfo; }