| Author |
Message |
< Advanced Erlang/OTP ~ send structure with erlang and gen_tcp |
| klm |
Posted: Tue May 12, 2009 11:34 am |
|
|
|
User
Joined: 11 May 2009
Posts: 18
|
hello,
I'm new on erlang and I have to do a P2P program.
I would like to know if it was possible to send structure with erlang and gen_tcp.
I only saw that I could send string of char messages and I don't want to have to parse the messages.It will be easily to send preformated messages as a structure or a list of structure.(As in the C language).
excuse for my english
thanks |
|
|
| Back to top |
|
| klm |
Posted: Tue May 12, 2009 12:58 pm |
|
|
|
User
Joined: 11 May 2009
Posts: 18
|
I don't ask for a solution (but if you have I'm interested too ) I just want to know if it's possible.
I think that I'm not the first who wants to communicate between 2 programs in erlang. So what's are your solutions.
I know I write bad english so if you don't understand something in my problem don't hesitate to ask me precisions.
thanks ! |
|
|
| Back to top |
|
| klaar |
Posted: Sat May 16, 2009 7:38 pm |
|
|
|
User
Joined: 06 Oct 2008
Posts: 11
Location: Göteborg/Sweden
|
term_to_binary/1 encodes
binary_to_term/1 decodes
binary_to_term(term_to_binary({foo, bar})) returns {foo, bar}
Good luck with your project  |
|
|
| Back to top |
|
| Mazen |
Posted: Sun May 17, 2009 9:10 am |
|
|
|
User
Joined: 20 Jul 2006
Posts: 164
Location: London
|
| Also your English is fully understandable. Don't worry and good luck! |
|
|
| Back to top |
|
| klm |
Posted: Mon May 18, 2009 5:14 pm |
|
|
|
User
Joined: 11 May 2009
Posts: 18
|
ok thanks for your responses
I will see that tonight.
maybe it's easiest because I was trying to parse string of characters |
|
|
| Back to top |
|
| klm |
Posted: Mon May 18, 2009 7:16 pm |
|
|
|
User
Joined: 11 May 2009
Posts: 18
|
I try the functions but it didn't works
I think it's because I try to send a list of structure but I m not sure if the problem comes from this.
did you know if I can use the term_to_binary and binary_to_term function with a list of structure
as :
foo = {one,two},
bar = {three,four},
List = [foo,bar],
binary_to_term(term_to_binary(List)),
thanks for your responses |
|
|
| Back to top |
|
| klm |
Posted: Mon May 18, 2009 7:37 pm |
|
|
|
User
Joined: 11 May 2009
Posts: 18
|
I think I need to put the options binary into gen_tcp options
I saw that it was 2 options : list , binary
I put no option because I also send and use string. Is this compatible ?
I try to put the option binary to send a list but now I can't send strings of char.
can I use the function binary_to_term to send string and also list of structure ? or binary_to_term is only for structures ?
thanks ! |
|
|
| Back to top |
|
| klm |
Posted: Mon May 18, 2009 7:49 pm |
|
|
|
User
Joined: 11 May 2009
Posts: 18
|
In fact,
I try and I resolve my problem with the strings of char but I try to send my list of structure using the function list_to_binary and binary_to_list but I've got an error {badarg,terms_of_my_list}
did you know why I've got this error ?
thanks for your responses |
|
|
| Back to top |
|
| klm |
Posted: Mon May 18, 2009 8:00 pm |
|
|
|
User
Joined: 11 May 2009
Posts: 18
|
ok sorry,
I try to get help too early.
I finally resolve my probleme
I thought that I need to use list_to_binary to code a list because the word was in both but not at all
term_to_binary was the good function |
|
|
| Back to top |
|
|
|