Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  send structure with erlang and gen_tcp

klm
Posted: Tue May 12, 2009 11:34 am Reply with quote
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
View user's profile Send private message
klm
Posted: Tue May 12, 2009 12:58 pm Reply with quote
User Joined: 11 May 2009 Posts: 18
I don't ask for a solution (but if you have I'm interested too Smile ) 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 !
View user's profile Send private message
klaar
Posted: Sat May 16, 2009 7:38 pm Reply with quote
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 Smile
View user's profile Send private message
Mazen
Posted: Sun May 17, 2009 9:10 am Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
Also your English is fully understandable. Don't worry and good luck!
View user's profile Send private message
klm
Posted: Mon May 18, 2009 5:14 pm Reply with quote
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
View user's profile Send private message
klm
Posted: Mon May 18, 2009 7:16 pm Reply with quote
User Joined: 11 May 2009 Posts: 18
I try the functions but it didn't works Sad

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
View user's profile Send private message
klm
Posted: Mon May 18, 2009 7:37 pm Reply with quote
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 !
View user's profile Send private message
klm
Posted: Mon May 18, 2009 7:49 pm Reply with quote
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
View user's profile Send private message
klm
Posted: Mon May 18, 2009 8:00 pm Reply with quote
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 Smile

term_to_binary was the good function
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum