BrandonPotter / SimpleTCP

Straightforward .NET library to handle the repetitive tasks of spinning up and working with TCP sockets (client and server).
Apache License 2.0
363 stars 108 forks source link

Server send message to client #56

Closed Xinnony closed 5 years ago

Xinnony commented 5 years ago

Hi, how the server can send a message to a specific client ? I can use Broadcast but is not good.

Do you have a solution ?

Xinnony commented 5 years ago

Finally i use another Framework https://github.com/hikalkan/scs

twhalen08 commented 3 years ago

I am trying to figure this one out myself. I believe this is possible by adding another method to SimpleTCPServer.CS similar to...

public void Broadcast(byte[] data) { foreach(var client in _listeners.SelectMany(x => x.ConnectedClients)) { client.GetStream().Write(data, 0, data.Length); } }

but I am getting hung up on the lambda expression. Any chance anyone can help me out? I believe i could have a method like this that also takes in an IP address and port and then in the lambda area there, I would think you could select only the specific client from the dictionary that you want and send a message to that specific client.

Any help here would be super appreciated.