Exemplo n.º 1
0
    private void ListenerCallback(IAsyncResult result)
    {
        HttpListenerContext context = listener.EndGetContext(result);

        Stream stream = context.Request.InputStream;

        int read = 0;

        byte[] buffer = new byte[1024];

        read = stream.Read(buffer, 0, buffer.Length);

        string json = Encoding.ASCII.GetString(buffer, 0, read);

        if (smsMessagingImpl != null)
        {
            if (json.Contains("deliveryInfoNotification"))
            {
                DeliveryInfoNotification deliveryInfoNotification = smsMessagingImpl.ConvertJsonToDeliveryInfo(json);
                if (smsMessagingImpl.DeliveryStatusNotificationPushListeners != null)
                {
                    for (int i = 0; i < smsMessagingImpl.DeliveryStatusNotificationPushListeners.Count; i++)
                    {
                        smsMessagingImpl.DeliveryStatusNotificationPushListeners[i].OnDeliveryStatusNotificationReceived(deliveryInfoNotification);
                    }
                }
            }
            else if (json.Contains("inboundSMSMessage"))
            {
                if (smsMessagingImpl != null)
                {
                    if (smsMessagingImpl.DeliveryStatusNotificationPushListeners != null)
                    {
                        InboundSMSMessageList smsMessagesList = smsMessagingImpl.ConvertJsonToInboundSMSMessageList(json);
                        for (int i = 0; i < smsMessagingImpl.InboundMessagePushListeners.Count; i++)
                        {
                            smsMessagingImpl.InboundMessagePushListeners[i].OnMessageReceived(smsMessagesList);
                        }
                    }
                }
            }
        }
        else if (hlrClientImpl != null)
        {
            if (json.Contains("terminalRoamingStatusList"))
            {
                if (hlrClientImpl.HlrPushListeners != null)
                {
                    RoamingNotification roamingNotification = hlrClientImpl.ConvertJsonToRoamingNotification(json);
                    for (int i = 0; i < smsMessagingImpl.DeliveryStatusNotificationPushListeners.Count; i++)
                    {
                        hlrClientImpl.HlrPushListeners[i].OnHLRReceived(roamingNotification);
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
        private static void StartServer()
        {
            try
            {
                IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, port);

                server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                server.Bind(ipEnd);
                server.Listen(100);

                while (running)
                {
                    Socket clientSock = server.Accept();

                    byte[] clientData       = new byte[4096];
                    int    receivedBytesLen = clientSock.Receive(clientData);

                    string   receivedData    = Encoding.ASCII.GetString(clientData, 0, receivedBytesLen);
                    string[] arrReceivedData = System.Text.RegularExpressions.Regex.Split(receivedData, "\r\n\r\n");

                    if (arrReceivedData.Length == 2)
                    {
                        string json = arrReceivedData[1];

                        if (json.Trim().Length > 0)
                        {
                            if (json.Contains("deliveryInfoNotification"))
                            {
                                if (smsMessagingImpl != null)
                                {
                                    DeliveryInfoNotification deliveryInfoNotification = smsMessagingImpl.ConvertJsonToDeliveryInfo(json);
                                    if (smsMessagingImpl.DeliveryStatusNotificationPushListeners != null)
                                    {
                                        for (int i = 0; i < smsMessagingImpl.DeliveryStatusNotificationPushListeners.Count; i++)
                                        {
                                            smsMessagingImpl.DeliveryStatusNotificationPushListeners[i].OnDeliveryStatusNotificationReceived(deliveryInfoNotification, null);
                                        }
                                    }
                                }
                            }
                            else if (json.Contains("inboundSMSMessage"))
                            {
                                Console.WriteLine(json);

                                if (smsMessagingImpl != null)
                                {
                                    if (smsMessagingImpl.DeliveryStatusNotificationPushListeners != null)
                                    {
                                        InboundSMSMessageList smsMessagesList = smsMessagingImpl.ConvertJsonToInboundSMSMessageList(json);
                                        for (int i = 0; i < smsMessagingImpl.InboundMessagePushListeners.Count; i++)
                                        {
                                            smsMessagingImpl.InboundMessagePushListeners[i].OnMessageReceived(smsMessagesList, null);
                                        }
                                    }
                                }
                                else if (json.Contains("terminalRoamingStatusList"))
                                {
                                    if (hlrClientImpl != null)
                                    {
                                        if (hlrClientImpl.HlrPushListeners != null)
                                        {
                                            RoamingNotification roamingNotification = hlrClientImpl.ConvertJsonToRoamingNotification(json);
                                            for (int i = 0; i < smsMessagingImpl.DeliveryStatusNotificationPushListeners.Count; i++)
                                            {
                                                hlrClientImpl.HlrPushListeners[i].OnHLRReceived(roamingNotification, null);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (LOGGER.IsErrorEnabled)
                {
                    LOGGER.Error(e.Message);
                }

                //Stop();

                Console.WriteLine(e.Message);
            }
        }