[erlang-questions] Sending UDP packets

Oscar Muñoz Garrigós osmuogar@REDACTED
Fri Aug 21 14:15:02 CEST 2015


Hi,
I am using a server to send some packets. The problem is actually the
packets are truncated and my client does not receive the full packet. I
created two sockets but only the socket wich receives the packet returns it
to the client, if i change it the packet is lost. Could you give me some
advice?

Here is the code:



-behaviour(gen_server).
init(_Args)->
    ...
    {ok,Socket} = gen_udp:open(49900),
    {ok, #state{socket=Socket}}.

handle_info(Info, State)->
    error_logger:info_msg("Received via INFO: ~p~n", [Info]),
    {udp, Socket, IP, InPortNo, Packet} = Info,
    [{"from",From},{"to",To},{"text",Text}] = parser:read_xml(Packet),

    write_to_db(Socket, IP, InPortNo, From, To, Text),
    {noreply, State}.

write_to_db(WSocket, WAdress, WMPort, WFrom, WTo, WText)->
     ...
     ...
    Message = analizar_resultados(Respuesta),

    {ok, SSocket} = gen_udp:open(0,[inet]),
    %%ok = gen_udp:send(SSocket, WAdress, WMPort, Message), <-------- This
does not works cause the packet is lost
    ok = gen_udp:send(WSocket, WAdress, WMPort, Message), <-------- This
works but the packet is truncated
    gen_udp:close(SSocket),
    ok.





Thank you all for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150821/8f47dc1a/attachment.htm>


More information about the erlang-questions mailing list