Вопрос

I'm planning to use an instance of DatagramSocket and call its send method from different threads... to send UDP packets to different clients. Is the method thread safe i.e. calling this method from different threads will not create any trouble/inconsistency/race condition?

Thanks!

Это было полезно?

Решение 2

UDP guarantees that datagrams arrive intact (if at all). In other words there can be no interleaving even if there is multithreading at the sender. That's all you need. You don't actually need thread safety. However the C send() system call is thread safe, like all system calls, because they are atomic.

Другие советы

Yes. This is only a thin layer on the native OS, which is threadsafe.

See here http://www.velocityreviews.com/forums/t150685-is-datagramsocket-thread-safe.html

The answer is yes, the layer on the native operating system is thread safe.

BUT, because network throughput is limited, if you send more packets than the network can handle, some packets will be dropped.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top