0

I am new to .NET (C#) and websockets... I have installed VS2012 and Windows Server 2012 and have websockets up and running. What I can't seem to do is receive a message from one socket and send it to another, specific socket. The only option seems to be to broadcast the message to all sockets. Is there a way to target messages to only specific users? I want the chat room moderator to have the chance to reject inappropriate posts.

  • Assuming you have all your clients (i.e., socket objects) within an array in your server-side script, why not just loop through the array and use if statements or similar logic to restrict which clients you send info to? – HartleySan Jan 30 '13 at 03:35
  • Once I find the particular client I am looking for what is the method for sending a message to only that client? The only method I can see in MS Server 2012 is 'Broadcast()', which sends to the entire collection. Is there another way? – Stephen Grimes Jan 30 '13 at 13:39
  • I use PHP for my server-side language, so I can't provide exact code for you, but I imagine that MS Server 2012 has a particular function for sending data along a specified socket. I'd check out an MS Server 2012 socket reference for details, and find the function that allows you to send data along a specified socket. That should get you there. – HartleySan Jan 30 '13 at 13:54
  • Hartley, I thank you for your help. If there is a function to send the message to only one socket I have not found it. The way I solved my problem was to create multiple collections (in some cases having only one member) and then broadcasting to "all" members in a collection. Ugly, but it works. Thanks Again – Stephen Grimes Feb 05 '13 at 20:48
  • Related to this: http://stackoverflow.com/a/15474698/39904 Use a PubSub layer and consider authentication. In this case I'd also consider looking at http://signalr.net/ – leggetter Mar 18 '13 at 10:37

1 Answers1

1

The recommended approach is setting up some sort of routing scheme to ensure that a message can be delivered to a specific user. E.g. Pubnub uses channels for message routing. To prevent multiple connections to your server, you could consider multiplexing channels on the server-side into a single socket.

To implement moderation, you have some additional challenges to keep in mind; Think about placing incoming messages into a moderation queue for approval. A message queue like ZeroMQ or RabbitMQ would work for this. A moderator would pull messages from the queue and either approve the message for final broadcast, or reject (dropping the message on the floor).

Jason Oster
  • 1,386
  • 1
  • 13
  • 17