void TcpConnection_OpenConnection(Exception e) { SmppBindRes responsePdu = null; Exception processException = null; lock (this) { try { if ((e == null) && TcpConnection.Connected) { var asyncObject = PendingBind[0] as SmppAsyncObject; SendReqPdu(asyncObject.Request, ref asyncObject); responsePdu = new SmppBindRes(asyncObject.PduRes); if (responsePdu.Header.CommandStatus != 0) { TcpConnection.Disconnect(); } else { LastBindRes = responsePdu; PendingResponse.Clear(); ConnectionSuccess = true; } } else { processException = e; } } catch (Exception exception2) { processException = exception2; } Binding = false; PendingBindResTrigger(responsePdu, processException); } }
public SmppBindRes Bind() { if ((_InternalConnection != null) && _InternalConnection.Connected) { throw new SmppException("Error Connecting: The connection is already Open."); } switch (_Settings.Recycling.Method) { case SmppSettings.RecyclingMethod.Pooling: _InternalConnection = SmppPoolManager.GetConnection(_Settings); break; case SmppSettings.RecyclingMethod.Sharing: _InternalConnection = SmppShareManager.GetConnection(_Settings); break; default: _InternalConnection = new SmppInternalConnection(_Settings); break; } SetEvents(); SmppBindRes res = null; if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) && ((_InternalConnection.LastBindRes.Header != null) && (_InternalConnection.LastBindRes.Header.CommandStatus == 0))) { return(_InternalConnection.LastBindRes); } res = _InternalConnection.Bind(); _InternalConnection.LastBindRes = res; return(res); }
internal void BeginUnBind() { if (TcpConnection.Connected) { SendResPdu(new SmppUnBindReq().ToByteArray()); TcpConnection.Disconnect(); } LastBindRes = null; }
internal void UnBind() { if (TcpConnection.Connected) { var requestPdu = new SmppUnBindReq(); var asyncObject = new SmppAsyncObject(); SendReqPdu(requestPdu, ref asyncObject); TcpConnection.Disconnect(); } LastBindRes = null; }
void PendingBindResTrigger(SmppBindRes ResponsePdu, Exception ProcessException) { foreach (SmppAsyncObject obj2 in PendingBind) { var e = new SmppAsyncBindResEventArgs(); e._State = obj2.State; e._ProcessException = ProcessException; e._RequestPdu = obj2.Request as SmppBindReq; e._ResponsePdu = ResponsePdu; var callback = obj2.Callback as SmppBindResHandler; callback(this, e); } PendingBind.Clear(); }
internal SmppBindRes Bind() { SmppBindRes res = null; SmppBindReq requestPdu = null; lock (this) { try { if (Connected) { throw new Exception("You must disconnect before connect again", new SocketException(0x186a1)); } TcpConnection.RemoteHost = Settings.RemoteHost; TcpConnection.RemotePort = Settings.RemotePort; TcpConnection.LocalHost = Settings.LocalHost; TcpConnection.LocalPort = Settings.LocalPort; TcpConnection.BufferSize = Settings.SocketBufferSize; ConnectionSuccess = false; TcpConnection.Connect(); } catch (Exception exception) { _LastException = exception; res = new SmppBindRes(new SmppHeader(Settings.ConnectionMode.Value, GetSequenceNumber())); res.Header.CommandStatus = 0x15f95; return(res); } requestPdu = new SmppBindReq(Settings.ConnectionMode.Value, GetSequenceNumber(), Settings.BindParams); var asyncObject = new SmppAsyncObject(); SendReqPdu(requestPdu, ref asyncObject); res = new SmppBindRes(asyncObject.PduRes); if (res.Header.CommandStatus != 0) { TcpConnection.Disconnect(); return(res); } PendingResponse.Clear(); ConnectionSuccess = true; } return(res); }
public SmppAsyncBindResEventArgs(SmppBindRes ResponsePdu) { _ResponsePdu = ResponsePdu; }
/// <summary> /// -------------> /// </summary> public void Connect() { try { if (tProtocol.ProtocolVersion < 3.4) { // Transmitter if (!smppconn.Connected) { try { try { ResBind = smppconn.Bind(); } catch (SmppTimeOutException errtime) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ":" + errtime.Message + "\n"); } } catch (SmppGenericNackException egn2) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ":" + egn2.Message + "\n"); } if (smppconn.Connected == true) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + " Transmitter Client Connected Successfully\n"); } } if (!smppconn2.Connected) { try { try { ResBind2 = smppconn2.Bind(); // Receiver } catch (SmppTimeOutException errtime) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ":" + errtime.Message + "\n"); } } catch (SmppGenericNackException egn1) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ":" + egn1.Message + "\n"); } if (smppconn2.Connected == true) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + " Receiver Client Connected Successfully\n"); } } } else { if (!smppconn.Connected) { try { try { //cyberspace ResBind = smppconn.Bind(); // Tranceiver } catch (SmppTimeOutException errtime) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ":" + errtime.Message + "\n"); } } catch (SmppGenericNackException egn) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ":" + egn.Message + "\n"); } if (smppconn.Connected == true) { logger.Info(tProtocol.NetworkID + ":" + tProtocol.OperatorID + " Tranceiver Client Connected Successfully\n"); } } } enquireTimer.Enabled = true; } catch (SmppException ex) { logger.Error(tProtocol.NetworkID + ":" + tProtocol.OperatorID + ": " + ex.Message + "\n"); } }
public int BindRes(Guid ConnGuid, SmppBindRes ResponsePdu) { return(TcpServer.Send(ConnGuid, ResponsePdu.ToByteArray())); }