Erlang open socket or know?

Use erlang:port_info/1 It returns undefined if the socket is closed. For example.

Use erlang:port_info/1. It returns undefined if the socket is closed. For example: Eshell V5.8.3 (abort with ^G) 1> {ok,S} = gen_tcp:connect("localhost", 8000, binary,{active,false}).

{ok,#Port} 2> erlang:port_info(S). {name,"tcp_inet"}, {links,}, {id,634}, {connected,}, {input,0}, {output,0} 3> gen_tcp:close(S). Ok 4> erlang:port_info(S).

Undefined But be careful about using this for defensive programming, as that's not the Erlang way. It's better to make your code assume the socket is open, and if it hits an error because it tries to use an already-closed socket, let it crash and let something else like a supervisor handle the error.

This opens a client socket, not a server. – rvirding Apr 19 at 18:31 @rvirding True, but I must be missing your point -- you can replace the gen_tcp:connect call above with a call to gen_tcp:listen or gen_tcp:accept for example and call erlang:port_info/1 on the sockets they return with the same results as the connect example shows. – Steve Vinoski Apr 19 at 23:59 Yes, of course, it will.My comment was just pointing out that this code was an example of how you open a client socket.

For a server socket you need to use gen_tcp:listen and gen_tcp:accept as you said in your comment. – rvirding Apr 20 at 23:02.

Try this in your terminal when your app reaches the point at which you want to know inet:i().

My guess is that most socket functions will return an error tuple if the socket is not open.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions