public void SendPdu(SmppPdu pdu) { if (tcpClient == null || !tcpClient.Connected) { throw new Exception("Not connected"); } tcpClient.GetStream().Write(pdu.GetData(), 0, (int)pdu.Length); #if DEBUG Console.WriteLine("Sending: " + pdu); Console.WriteLine(); #endif }
private void ReceivingThread() { try { int b; do { b = tcpClient.GetStream().ReadByte(); if (b >= 0) { data.WriteByte((byte)b); if (data.Length == 4) { var buf = data.GetBuffer(); length = (uint)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); } if (data.Length == length) { OnSmppPduReceived(this, SmppPdu.CreateFromBytes(data.GetBuffer(), length)); data = new MemoryStream(); length = 0; } } } while (tcpClient != null && tcpClient.Connected && b >= 0); } catch { } finally { if (tcpClient != null) { tcpClient.Close(); tcpClient = null; } receiveThread = null; OnDisconnected(this); } }
void SmppConnection_OnSmppPduReceived(SmppClient sender, SmppPdu pdu) { switch (pdu.CommandId) { case SmppPdu.SmppCommandType.bind_transmitter: OnBindTransmitterReceived(this, (SmppPduBindTransmitter)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.bind_transmitter_resp: OnBindTransmitterRespReceived(this, (SmppPduBindTransmitterResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.bind_receiver: OnBindReceiverReceived(this, (SmppPduBindReceiver)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.bind_receiver_resp: OnBindReceiverRespReceived(this, (SmppPduBindReceiverResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.bind_transceiver: OnBindTransceiverReceived(this, (SmppPduBindTransceiver)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.bind_transceiver_resp: OnBindTransceiverRespReceived(this, (SmppPduBindTransceiverResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.unbind: OnUnbindReceived(this, (SmppPduUnbind)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.unbind_resp: OnUnbindRespReceived(this, (SmppPduUnbindResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.generic_nack: OnGenerickNackReceived(this, (SmppPduGenerickNack)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.submit_sm: OnSubmitSmReceived(this, (SmppPduSubmitSm)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.submit_sm_resp: OnSubmitSmRespReceived(this, (SmppPduSubmitSmResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.deliver_sm: OnDeliverSmReceived(this, (SmppPduDeliverSm)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.deliver_sm_resp: OnDeliverSmRespReceived(this, (SmppPduDeliverSmResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.data_sm: OnDataSmReceived(this, (SmppPduDataSm)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.data_sm_resp: OnDataSmRespReceived(this, (SmppPduDataSmResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.query_sm: OnQuerySmReceived(this, (SmppPduQuerySm)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.query_sm_resp: OnQuerySmRespReceived(this, (SmppPduQuerySmResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.cancel_sm: OnCancelSmReceived(this, (SmppPduCancelSm)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.cancel_sm_resp: OnCancelSmRespReceived(this, (SmppPduCancelSmResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.enquire_link: OnEnquireLinkReceived(this, (SmppPduEnquireLink)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.enquire_link_resp: OnEnquireLinkRespReceived(this, (SmppPduEnquireLinkResp)SmppPdu.CreateFromBytes(pdu.GetData())); break; case SmppPdu.SmppCommandType.alert_notification: OnAlertNotificationReceived(this, (SmppPduAlertNotification)SmppPdu.CreateFromBytes(pdu.GetData())); break; } }
public void SendPdu(SmppPdu pdu) { if (tcpClient == null || !tcpClient.Connected) throw new Exception("Not connected"); tcpClient.GetStream().Write(pdu.GetData(), 0, (int)pdu.Length); #if DEBUG Console.WriteLine("Sending: " + pdu); Console.WriteLine(); #endif }
public static SmppPdu CreateFromBytes(byte[] bytes, uint length) { var pdu = new SmppPdu(bytes, length); switch (pdu.CommandId) { case SmppCommandType.bind_receiver: return(new SmppPduBindReceiver(bytes, length)); case SmppCommandType.bind_receiver_resp: return(new SmppPduBindReceiverResp(bytes, length)); case SmppCommandType.bind_transceiver: return(new SmppPduBindTransceiver(bytes, length)); case SmppCommandType.bind_transceiver_resp: return(new SmppPduBindTransceiverResp(bytes, length)); case SmppCommandType.bind_transmitter: return(new SmppPduBindTransmitter(bytes, length)); case SmppCommandType.bind_transmitter_resp: return(new SmppPduBindTransmitterResp(bytes, length)); case SmppCommandType.outbind: return(new SmppPduOutbind(bytes, length)); case SmppCommandType.unbind: return(new SmppPduUnbind(bytes, length)); case SmppCommandType.unbind_resp: return(new SmppPduUnbindResp(bytes, length)); case SmppCommandType.enquire_link: return(new SmppPduEnquireLink(bytes, length)); case SmppCommandType.enquire_link_resp: return(new SmppPduEnquireLinkResp(bytes, length)); case SmppCommandType.generic_nack: return(new SmppPduGenerickNack(bytes, length)); case SmppCommandType.deliver_sm: return(new SmppPduDeliverSm(bytes, length)); case SmppCommandType.submit_sm: return(new SmppPduSubmitSm(bytes, length)); case SmppCommandType.deliver_sm_resp: return(new SmppPduDeliverSmResp(bytes, length)); case SmppCommandType.submit_sm_resp: return(new SmppPduSubmitSmResp(bytes, length)); case SmppCommandType.data_sm: return(new SmppPduDataSm(bytes, length)); case SmppCommandType.data_sm_resp: return(new SmppPduDataSmResp(bytes, length)); case SmppCommandType.query_sm: return(new SmppPduQuerySm(bytes, length)); case SmppCommandType.query_sm_resp: return(new SmppPduQuerySmResp(bytes, length)); case SmppCommandType.cancel_sm: return(new SmppPduCancelSm(bytes, length)); case SmppCommandType.cancel_sm_resp: return(new SmppPduCancelSmResp(bytes, length)); case SmppCommandType.replace_sm: return(new SmppPduReplaceSm(bytes, length)); case SmppCommandType.replace_sm_resp: return(new SmppPduReplaceSmResp(bytes, length)); case SmppCommandType.alert_notification: return(new SmppPduAlertNotification(bytes, length)); } throw new NotSupportedException(string.Format("Command {0} is not supported", pdu.CommandId)); }
public static SmppPdu CreateFromBytes(byte[] bytes, uint length) { var pdu = new SmppPdu(bytes, length); switch (pdu.CommandId) { case SmppCommandType.bind_receiver: return new SmppPduBindReceiver(bytes, length); case SmppCommandType.bind_receiver_resp: return new SmppPduBindReceiverResp(bytes, length); case SmppCommandType.bind_transceiver: return new SmppPduBindTransceiver(bytes, length); case SmppCommandType.bind_transceiver_resp: return new SmppPduBindTransceiverResp(bytes, length); case SmppCommandType.bind_transmitter: return new SmppPduBindTransmitter(bytes, length); case SmppCommandType.bind_transmitter_resp: return new SmppPduBindTransmitterResp(bytes, length); case SmppCommandType.outbind: return new SmppPduOutbind(bytes, length); case SmppCommandType.unbind: return new SmppPduUnbind(bytes, length); case SmppCommandType.unbind_resp: return new SmppPduUnbindResp(bytes, length); case SmppCommandType.enquire_link: return new SmppPduEnquireLink(bytes, length); case SmppCommandType.enquire_link_resp: return new SmppPduEnquireLinkResp(bytes, length); case SmppCommandType.generic_nack: return new SmppPduGenerickNack(bytes, length); case SmppCommandType.deliver_sm: return new SmppPduDeliverSm(bytes, length); case SmppCommandType.submit_sm: return new SmppPduSubmitSm(bytes, length); case SmppCommandType.deliver_sm_resp: return new SmppPduDeliverSmResp(bytes, length); case SmppCommandType.submit_sm_resp: return new SmppPduSubmitSmResp(bytes, length); case SmppCommandType.data_sm: return new SmppPduDataSm(bytes, length); case SmppCommandType.data_sm_resp: return new SmppPduDataSmResp(bytes, length); case SmppCommandType.query_sm: return new SmppPduQuerySm(bytes, length); case SmppCommandType.query_sm_resp: return new SmppPduQuerySmResp(bytes, length); case SmppCommandType.cancel_sm: return new SmppPduCancelSm(bytes, length); case SmppCommandType.cancel_sm_resp: return new SmppPduCancelSmResp(bytes, length); case SmppCommandType.replace_sm: return new SmppPduReplaceSm(bytes, length); case SmppCommandType.replace_sm_resp: return new SmppPduReplaceSmResp(bytes, length); case SmppCommandType.alert_notification: return new SmppPduAlertNotification(bytes, length); } throw new NotSupportedException(string.Format("Command {0} is not supported", pdu.CommandId)); }