private void perConnection(Socket client) { EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0); int recv = 0; byte[] data = new byte[1024]; while (true) { try { recv = 0; data = new byte[1024]; recv = client.Receive(data); string messageSendFromClient = Encoding.ASCII.GetString(data, 0, recv); string command = Regex.Match(messageSendFromClient, "<Command>(.*?)</Command>").Groups[1].Value; string topicName = Regex.Match(messageSendFromClient, "<Topic>(.*?)</Topic>").Groups[1].Value; string text = Regex.Match(messageSendFromClient, "<Text>(.*?)</Text>").Groups[1].Value; Console.WriteLine(messageSendFromClient); Console.WriteLine("Regex: " + command); if (!string.IsNullOrEmpty(command)) { if (command == "Publish") { if (!string.IsNullOrEmpty(topicName)) { string message = "Topic: " + topicName + "\nText: " + text; List <Subscriber> subscriberListForThisTopic = TransientData.GetSubscribers(topicName); ConnectionParameters connectionParameters = new ConnectionParameters(); connectionParameters.Server = client; connectionParameters.Message = message; connectionParameters.SubscriberListForThisTopic = subscriberListForThisTopic; Publish(connectionParameters); } } } } catch { } } }
private void perConnection(Socket client) { int recv = 0; byte[] data = new byte[1024]; while (true) { recv = 0; data = new byte[1024]; try { recv = client.Receive(data); } catch (SocketException e) { break; } string messageSendFromClient = Encoding.ASCII.GetString(data, 0, recv); string[] messageParts = messageSendFromClient.Split(",".ToCharArray()); Console.WriteLine(messageSendFromClient); if (!string.IsNullOrEmpty(messageParts[0])) { switch (messageParts[0]) { case "Connect": _deadLetterChannel.Check(messageParts[1], client); break; case "Subscribe": if (!string.IsNullOrEmpty(messageParts[1])) { Subscriber subscriber = new Subscriber(); subscriber.ID = messageParts[2]; subscriber.Client = client; TransientData.AddSubscriber(messageParts[1], subscriber); _deadLetterChannel.Check(messageParts[2], client); } break; case "UnSubscribe": if (!string.IsNullOrEmpty(messageParts[1])) { Subscriber subscriber = new Subscriber(); subscriber.ID = messageParts[2]; subscriber.Client = client; TransientData.RemoveSubscriber(messageParts[1], subscriber); } break; } } } }