0

I am currently working on a way to send packets to a UDP multicast session.

Here is my current code (just listening):

-module(zcclient).

-export([open/2,start/0]).
-export([stop/1,receiver/0]).

open(Addr,Port) ->
   {ok,S} = gen_udp:open(Port,[{reuseaddr,true}, {ip,Addr}, {multicast_ttl,4}, {multicast_loop,fa$
   inet:setopts(S,[{add_membership,{Addr,{225,0,0,111}}}]),
   S.

close(S) -> gen_udp:close(S).

start() ->
   S=open({225,0,0,111},12175),
   Pid=spawn(?MODULE,receiver,[]),
   gen_udp:controlling_process(S,Pid),
   {S,Pid}.

stop({S,Pid}) ->
   close(S),
   Pid ! stop.

receiver() ->
   receive
       {udp, _Socket, IP, InPortNo, Packet} ->
           io:format("~n~nFrom: ~p~nPort: ~p~nData: ~p~n",[IP,InPortNo,Packet]),
           receiver();
       stop -> true;
       AnythingElse -> io:format("RECEIVED: ~p~n",[AnythingElse]),
           receiver()
   end.

It basically listens to the specified multicast IP and outputs From, Port and the Data.

The goal is to be able to send some packets back as well.

N3sh
  • 881
  • 8
  • 37
  • Are you asking us to reverse engineer the packet format? – PlasmaHH Feb 22 '13 at 10:23
  • I was just wondering whether I could get that packet in Hex or something – N3sh Feb 22 '13 at 10:28
  • 1
    [This question](http://stackoverflow.com/q/3768197/113848) has some proposals for printing a binary as hexadecimal numbers. – legoscia Feb 22 '13 at 10:31
  • I have just updated the question as I had written it in an improper way. Thanks legoscia for the quick answer :) – N3sh Feb 22 '13 at 10:40
  • There still doesn't seem to be a question in your question. What particular problem do you need help solving? – kjw0188 Feb 23 '13 at 02:35

1 Answers1

2

in cpp:

struct student{ int32 id; int32 grade; int32 class;};

...

in erlang

<<id:32, grade:32, class:32>>

...

it`s simple,u must know the protocol in either language. when u receive "AnyThingElse" in erlang, just

<<data1:32, data2:16, data3:8, ....>> = AnyThingElse,

in erlang it`s simple to use binary data. i love erlang

new7877
  • 87
  • 2