1

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

1 Answer 1

1

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?
Sign up to request clarification or add additional context in comments.

3 Comments

i checked sockedarray in debug and it has right socket i checked their remote ip it looked okey. There is no exception whatsoever like i told on the request side it works fine. But i want other clients to get request same requesting client. I dont know what is NoDelay
@EmirhanÖzsoy NoDelay is a boolean on Socket; you probably want it to be true. However, ultimately I strongly suspect that the problem here is more client-related than server-related. The code looks OK.
Thanks i did it! Problem was in the code it starts listening when i get request so other clients wasnt starting to listening without request not it is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.