1

Could you please help me? I've a problem related with the gen_tcp send function. I've been trying to send few tuples, about 10-15 items, which were decoded to amf objects, from my erlang server to my flash client.

case get_tcp:send(Socket, Msg) of
ok -> io:format("sent~n");
{erorr, Err} -> io:format("~w~n", [Err])
end

No errors but the flash client doesn't recieve whole data just about 8-11 items. The socket options are [binary, {active, true}, {reuseaddr, true}]. I've checked my network where I use the client - sent packets were fragmented into two fragments, big and small ones. The big one is the first fragment of packet and small one is the next. Amount of the bigs is the same as amount of sent messages, but the smalls are much less and about number of received messages by the flash client.

It only reproduces if I send data fast, if I do it slowly it seems ok. Does anyone know why it happens? It will be very helpful.

TacticalCoder
  • 6,275
  • 3
  • 31
  • 39
Sergey
  • 11
  • 1
  • What do you mean by "I send data fast"? Is it possible that you run out of buffer memory and packages are dropped? Are you sure you read data correctly on other end? What does wireshark show? – Łukasz Milewski Mar 19 '12 at 08:57

3 Answers3

1

My guess is that this is a framing issue.

TCP is a streaming protocol, so when you read in flash, you are not guaranteed to get all the messages right away. Rather you need some kind of framing setup, say {packet, 2} or {packet, 4} on the socket options. This effectively turns TCP from a streaming protocol into a messaging protocol. And I think you want the latter.

I GIVE CRAP ANSWERS
  • 18,739
  • 3
  • 42
  • 47
1

I think you can do like this: 1 Before send msg(your tuple), use term_to_binary(Msg) to get binary, then sizeof the binary, then, after your client receive the msg, use binary_to_term to get tuple. 2 Both the client and server you need to set the socket option{packet, 2 or 4}

david.liu
  • 23
  • 2
0
  1. I not tried amf, but I use erlang+flash and json instead of amf
  2. What packet option of socket? (I use {packet, 2}, for example)
  3. How did you read data on client side? Maybe you not read all data to end and no new events raised?
Sergey Miryanov
  • 1,820
  • 16
  • 29