Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  puzzled by gen:tcp

jackson1668
Posted: Tue Dec 22, 2009 6:20 am Reply with quote
Joined: 15 Dec 2009 Posts: 1
When I try to use this module to create a simple server/client model based on sock,there is something unusual.
The source of the socket-server as below:
###################################################
-module(socket_server).
-export([start_nano_server/0]).

start_nano_server() ->
{ok,Listen} = gen_tcp:listen(31385,[binary,{packet,4},{reuseaddr,true},{active,true}]),
{ok,Socket} = gen_tcp:accept(Listen),
gen_tcp:close(Listen),
loop(Socket).

loop(Socket) ->
receive
{tcp,Socket,Bin} ->
io:format("Server received binary = ~p~n",[Bin]),
Str = binary_to_term(Bin),
io:format("Server (unpacked) ~p~n",[Str]),
Reply = Str,
io:format("Server replying = ~p~n",[Reply]),
gen_tcp:send(Socket,term_to_binary(Reply)),
loop(Socket);
{tcp_closed,Socket} ->
io:format("Server socket closed~n")
end.
####################################################
It`s works ok when I telnet it from locahost.
but when I try to connect it in other machine, it doesn`t work
(ps:When I use perl the create the server socket,I can connect the it from both machines.)
I hope you can help me,thank you very much!
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