Re: Is it portable, the unix domain socket one-to-one correspondence





On Dec 30, 6:40 am, "David Schwartz" <dav...@xxxxxxxxxxxxx> wrote:
Bin Chen wrote:
I just did a experiment to check the UNIX domain socket's behavior,
there is a client and server, client send the data to server, and
server receives. Actually, I want to know if I write separate multi
messages to the server's socket, will it be packaged to one big message
if the server are not quick enough to read each individual message.
Is it portable, I want to know can I rely on this? Is it POSIX
compliant? If each message can be assured by kernel to be not
concatenated to others, the message length can vary, and easy for the
IPC protocol design.You have two choices:

1) You can use UNIX domain stream sockets. These do not preserve
message boundaries but ensure reliable delivery.

2) You can use UNIX domain datagram sockets. These preserve message
boundaries but are only guaranteed reliable on some platforms.

Generally, the best solution when you need everything is to use UNIX
domain stream sockets and use some simple technique to specify the
message length. The following six techniques are commonly used:

1) If the message is text and never contains newlines, the message can
be delimited by a return/newline sequence.

2) If the message is text and contains multiple lines but never
contains an empty line, an empty line can be used to separate messages.

3) If the message is text and rarely contains empty lines, an empty
line can be used to separate messages and empty lines in a message can
be prefixed with a dot. If lines might start with a dot, you prefix
them with a dot as well. So ".foo" means "foo" and "..foo" means
".foo". "." means "end of message".

4) If the message is binary, you can include the message length before
each message. You can used a fixed number of bytes to encode the
message length in either a text or binary fashion.

5) If the message cannot contain a zero byte (if it's text), use a zero
byte to mark the end of a message. Use caution when processing such
messages in code because C uses a zero byte to mark the end of a
string.

6) If there is a character rarely used in the message, say 255, you can
change it into an escape character. The end of message can be marked by
a 255 followed by a 0. A 255 in the message can be encoded as two
255's. This leaves other escape sequences (like 255 1) for any purpose
you might come up with.

Thank you very much!

DS

.



Relevant Pages

  • Re: Non-Portal content not being returned in search results?
    ... On a separate note, I did manage to solve the WSS search problem. ... we had a single-server SPS 2003 solution running on SQL ... Server 2005 Express. ... that same server still hosts the SPS 2003 ...
    (microsoft.public.sharepoint.portalserver)
  • Re: Organization split - comments welcome
    ... Totally separate network; totally separate part of the city!! ... Or even being on the "same network". ... using Windows SBS 2003 Standard Edition. ... So, an additional server was purchased running Windows 2003 Server, ...
    (microsoft.public.windows.server.active_directory)
  • Re: MX lookup results different depending on client application
    ... Well it looks to me like your system has correct DNS settings, but you really need to get the non-working system's ip configuration to diagnose this problem. ... The mail server shows these results... ...
    (microsoft.public.windows.server.dns)
  • Re: New install partitioning question
    ... Dana, thank you so much for the quick reply. ... What you describe for the reasons to separate logs out to a separate ... I may be over-analyzing this for what this server will be doing. ...
    (microsoft.public.windows.server.setup)
  • Re: Updating Web Form Control From Thread
    ... > I have a web application running on a server, ... When a user opens the web app, ... > of my textboxes on the webform based on information that comes to the ... > Remember since I am polling, I get the information on a separate ...
    (microsoft.public.dotnet.framework.aspnet)

Loading