source

Is sending data via UDP sockets on the same machine reliable?

ittop 2023. 10. 29. 19:58
반응형

Is sending data via UDP sockets on the same machine reliable?

If i use UDP sockets for interprocess communication, can i expect that all send data is received by the other process in the same order?

I know this is not true for UDP in general.

No. I have been bitten by this before. You may wonder how it can possibly fail, but you'll run into issues of buffers of pending packets filling up, and consequently packets will be dropped. How the network subsystem drops packets is implementation-dependent and not specified anywhere.

In short, no. You shouldn't be making any assumptions about the order of data received on a UDP socket, even over localhost. It might work, it might not, and it's not guaranteed to.

아니요, 로컬 소켓이 있어도 그런 보장은 없습니다.순서대로 전송을 보장하는 IPC 메커니즘을 원하는 경우 다음과 같은 전이중 파이프를 사용하여 살펴볼 수 있습니다.popen(). 이렇게 하면 임의로 읽거나 쓸 수 있는 자식 프로세스의 파이프가 열립니다.주문 내 배송을 보장하며 동기식 또는 비동기식 I/O와 함께 사용할 수 있습니다 (select()아니면poll()), 응용 프로그램을 빌드하는 방법에 따라 달라집니다.

On unix there are other options such as unix domain sockets or System V message queues (some of which may be faster) but reading/writing from a pipe is dead simple and works. As a bonus it's easy to test your server process because it is just reading and writing from Stdio.

On windows you could look into Named Pipes, which work somewhat differently from their unix namesake but are used for precisely this sort of interprocess communication.

Loopback UDP is incredibly unreliable on many platforms, you can easily see 50%+ data loss. Various excuses have been given to the effect that there are far better transport mechanisms to use.

There are many middleware stacks available these days to make IPC easier to use and cross platform. Have a look at something like ZeroMQ or 29 West's LBM which use the same API for intra-process, inter-process (IPC), and network communications.

The socket interface will probably not flow control the originator of the data, so you will probably see reliable transmission if you have higher level flow control but there is always the possibility that a memory crunch could still cause a dropped datagram.

데이터그램에 대한 커널 메모리 할당을 제한하는 흐름 제어 없이는 네트워크 UDP만큼 신뢰할 수 없을 것이라고 생각합니다.

언급URL : https://stackoverflow.com/questions/2128701/is-sending-data-via-udp-sockets-on-the-same-machine-reliable

반응형