This is Sameer here.<br>I have used those lines in my code in client side of my program using "localhost" instead of IP address and its working fine.<br>For that 1st u have to run the server part with gen_tcp:listen() and then gen_tcp:accept().<br>
Then u can try to connect that socket from client side.<br>If u need then i can send the appropriate code also.<br><br>Here is the Example----><br> for Socket----><br><br>-module(socket11_server).<br>-export([start_server/0]).<br>
<br><br>start_server() -><br> {ok, Listen} = gen_tcp:listen(2345, [binary, {packet, 0},{reuseaddr, true},{active,true}]), <br> io:format("listen :~p~n",[Listen]),<br> {ok, Socket} = gen_tcp:accept(Listen),<br>
io:format("socket :~p~n",[Socket]),<br> gen_tcp:close(Listen),<br> loop(Socket).<br>loop(Socket) -><br> receive<br> {tcp, Socket, Bin} -><br> io:format("Server received binary = ~p~n",[Bin]),<br>
Str = binary_to_term(Bin),<br> io:format("Server (unpacked) ~p~n",[Str]),<br> {address_book,'addr@gunde2'}!Str,<br> loop(Socket);<br> {tcp_closed, Socket} -><br>
io:format("Server socket closed~n")<br> end.<br><br><br><br><br>And For client ----><br><br> -module(socket11_client).<br>-export([client_eval/0,loop/1]).<br><br>client_eval() -><br> case gen_tcp:connect("localhost" , 2345,[binary,{packet, 0}]) of<br>
{ok,Socket}-><br> io:format("Socket established~n"),<br> io:format("socket :~p~n",[Socket]),<br> register(client,spawn(?MODULE,loop,[Socket]));<br>
{error,Reason}-><br> io:format("Error on connect: ~s~n",[Reason])<br> end. <br> <br> <br> <br>loop(Socket)-><br> receive<br> {client,stop}-><br> io:format("client socket closed"), <br>
gen_tcp:close(Socket);<br> {client,Data}-><br> io:format("data is :::~p~n",[Data]),<br> ok = gen_tcp:send(Socket, term_to_binary(Data)),<br> io:format("~p~n",[Data]),<br>
loop(Socket);<br> {tcp,Socket,Bin} -><br> io:format("Client received binary= ~p ~n ",[Bin]),<br> Val = binary_to_term(Bin),<br> io:format("Client result=~p~n",[Val]) ,<br>
loop(Socket) <br> <br> end.<br><br> <br><br clear="all"><br>-- <br>Thanks & Regards<br>Sameer Prakash Pradhan<br>