Emirhan Özsoy
Emirhan Özsoy

Reputation: 43

C# TCP Socket Programming - Sending Data to All Sockets

I am working on server/multiple client programming. I will cut the chase everything is working well but

foreach(Socket sct in socketArray){
        sct.send(data);
}

is not working. It suppose to send data to all connected sockets but only the one who made request getting the response. I was thinking if it is related to tcp packaging? or i dont know why it is not working? If somebody can help i would be really appriciated. Thanks

Upvotes: 1

Views: 228

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062780

assuming data is byte[] and that you mean sct.Send, then: it should work fine, and send the same payload - sequentially - to all the sockets in socketArray. There isn't anything particularly nuanced here - each socket is independent.

Things to check:

  • does socketArray actually have the expected number of sockets?
  • are they the correct sockets?
  • is an exception happening?
  • are the sockets actually connected? (broken sockets are notoriously hard to detect reliably)
  • do you have NoDelay enabled?
  • is there some concurrency here that could mean that a single socket is trying to send twice at the same time?
  • is it sending, and the error is in the receive code?

Upvotes: 1

Related Questions