Re: How can I send many messages from a server to client in socket

From: Bob Hauck (postmaster_at_localhost.localdomain)
Date: 05/30/05


Date: Mon, 30 May 2005 08:30:17 -0400

On 30 May 2005 04:08:39 -0700, skprasat@gmail.com <skprasat@gmail.com>
wrote:

> what i need is to send these three char array in a single send
> function...

Maybe you could try writev().

But, because your question makes me think you are about to make a common
mistake, let me point out that sending the three arrays together will
not guarantee that all three will be returned together by a read() on
the other end. TCP does not guarantee that and if you assume it does
thne you _will_ get bitten sooner or later.

Instead, you should come up with some scheme for finding the start and
end of each message. If they are always strings, a null byte or NL will
work fine. Look for that token by calling read() in a loop rather than
assuming that the read() will return your whole string in one call.

-- 
 -| Bob Hauck
 -| A proud member of the reality-based community.
 -| http://www.haucks.org/


Relevant Pages

  • Re: FAQ Topic - How do I access a frames content? (2009-10-25)
    ... you are not reading any files "HTML or TXT, as it exists on disc" - ... you were getting so far "by using innerHTML ..., ... "Given an array of strings with the minimum 2 and the maximum 1o ... find the shortest common word in these strings. ...
    (comp.lang.javascript)
  • Re: 1 + 1 ==> True ???
    ... consistent on a particular implementation (e.g., here strings are ... doesn't make any sense in Python. ... don't know the type of an object you have and so can't guarantee that ... but also string concatenation) -- possible in a strongly-typed language ...
    (comp.lang.python)
  • Re: String containing algorithm
    ... >> which takes two Strings of any lengths and returns any letters which are ... > "longest common substring" search. ... > the set of common characters by intersecting the sets. ...
    (comp.lang.java.programmer)
  • Re: CONTINUE/EXIT
    ... // convert numbers to strings: ... var sNumber = new String; ... Rather than remembering how you're checking for nulls, numbers, etc. ... If you ever employ any common techniques to interrogate or manipulate ...
    (comp.databases.pick)
  • Re: Mother of all dumbass threads: What Liberal Bias?
    ... To receive standby rates, ... advertisers cannot be guaranteed a date when their ads will run, ... mistake," and that "the advertising representative failed to make it ... clear that for that rate the Times could not guarantee the Monday ...
    (rec.sport.golf)