[erlang-questions] tcp sockets - not clear

Oscar Hellström oscar@REDACTED
Tue Oct 7 18:42:17 CEST 2008


Hi,

See my comments embedded.

----- Original Message -----
From: "deepblue_other" <cktgatb@REDACTED>
To: erlang-questions@REDACTED
Sent: Monday, 6 October, 2008 12:07:02 PM GMT -08:00 US/Canada Pacific
Subject: Re: [erlang-questions] tcp sockets - not clear


thanks for the reply

Oscar Hellström-2 wrote:
> 
> Hi,
> 
> I'm assuming that a object is something running in a separate thread,
> which means that you will have to have a thread safe implementation of the
> send() function to be able to get the messages through without problems.
> AFAIK know at least the POSIX implementations are thread safe. Another
> important part here is that the whole message must be put on the wire
> before any part of any other message is, which actually means that the
> send() function need to support atomicy. If this is not the case for you
> send() function you probably need to serialise the sending. You can read
> more about this here:
> http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html
> 
well the flash VM does not support threading yet, so all the object
instances run in the same thread - thus thread safety is not an issue. 
you did nail it when saying that the whole message must be on the wire,
which is my original concern, but Im guessing that you guys might not be
able to answer this question since how Flash internally handles this is
somewhat undocumented. However I have a feeling that this is not an issue,
going back to the fact that Flash is single threaded. 
the question I guess is if a A is sent after B, TCP will ensure that A is
assembled correctly even if some parts of it come in after B. So TCP
guarantees that messages arrive in one peace (are assembled correctly) but
does not guarantee that they come in the order they were sent?

TCP guarantees that the messages do arrive in order. The only issue you might have is that described in the link posted earlier, but that is only relevant to multi-threaded applications. If you have a single thread then I can't see why all messages wouldn' be sent atomically.

Oscar Hellström-2 wrote:
> 
> Keep in mind that TCP packages can be fragmented on the way, and you need
> to assemble them yourself unless you use use the {packet, 1|2|4} option
> (and implement that on the flash side), i.e. you need some defined
> protocol. 
> 
you confused me here a bit. Im using {packet, 4} at the moment, but Im not
clear what I would have to do if it were {packet,0}, and what I have to do
on the Flash side. The packet assembling would not be handled automatically
by the TCP drivers on both Erlang and Flash side?

The {packet, 4} adds a four byte header which has the number of bytes in the package (big endian). This means that your client needs  to read four bytes, interpret them as an unsigned integer and then read that many bytes to get the whole package. I have no idea if this is built in in flash. If you use {packet, 0} you need to define you own protocol to state the payload of the message, or use some text based protocol where you can figure out if you need to read more or not by reading the message received.

Oscar Hellström-2 wrote:
> 
> If you're using a text based protocol this is less of a problem (or more
> depending on who you are) I guess.
> 
> From the erlang side we seem to have the same issue that we need to
> serialise the data to be absolutely sure that messages are not intervened
> (since the inet_drv.c essentially calls send() at some point). Someone
> please correct me if I'm wrong here.
> 
> Hope this helps.
> 
> ----- Original Message -----
> From: "deepblue_other" <cktgatb@REDACTED>
> To: erlang-questions@REDACTED
> Sent: Sunday, 5 October, 2008 9:07:08 AM GMT -08:00 US/Canada Pacific
> Subject: [erlang-questions]  tcp sockets - not clear
> 
> 
> hello everyone
> Im building a system with a Flash front-end and an Erlang back-end and
> have
> some confusion in a case where there is a single socket on the back-end
> per
> user (per single socket on the front-end).
> I want to have multiple independent objects on the front-end send messages
> to the back-end, but am not sure how the simultaneous transmission would
> be
> handled. This probably stems from my somewhat clowdly understanding of
> TCP.
> Say there are 3 objects that initiate a send() method on the front-end
> (almost at the same time) and send a semi large message each to the
> back-end. Each message would be ID'd by the front-end so that when
> received
> back it can be routed to the appropriate callback. Is this possible?
> since the packets are being assembled in the {tcp, Socket, Data} pattern
> match, peace by peace, would the correct peaces of the individual messages
> be stiched together? (doesnt seem like they would).
> 
> if that wont work then I would just have the serialize the
> sending/receiving, which is not too horrible...
> 
> thanks 
> -- 
> View this message in context:
> http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19826070.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
> 
> Best regards
> -- 
> Oscar Hellström, oscar@REDACTED
> Phone:  +44 (0)798 45 44 773
> Mobile: +44 (0)207 65 50 337
> Web:    http://www.erlang-consulting.com
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 

-- 
View this message in context: http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19844239.html
Sent from the Erlang Questions mailing list archive at Nabble.com.

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://www.erlang.org/mailman/listinfo/erlang-questions

-- 
Oscar Hellström, oscar@REDACTED
Phone:  +44 (0)798 45 44 773
Mobile: +44 (0)207 65 50 337
Web:    http://www.erlang-consulting.com




More information about the erlang-questions mailing list