Bad value on output port 'tcp_inet'

Jeff Crane jefcrane@REDACTED
Sun Aug 13 22:29:23 CEST 2006


I know this must come up a lot, but I have no idea how
I am messing this client up. I connect to a remote
scheme listener, but I cant seem to read back the
responses. Although the scheme listener catches it, I
am getting {error,einval} (from the listener? from the
program? from the socket?) and cannot read anything. 

The listener is a simple echo server.

-module(benign_client).

%% methods include
-export([start/2,test1/2]).
%% usage
%% benign_client:test("127.0.0.1",41)
start(Host,Port) ->
    spawn(fun() -> test1(Host,Port) end).

%% send a single message to the server wait for
%% a reply and close the socket

test1(Host,Port) ->
	case gen_tcp:connect(Host, Port, [binary,{packet,
0}]) of
		{ok, Socket} ->
			%% let me know about the socket
			io:format("Socket=~p~n",[Socket]),
			%% send a string with newline
			gen_tcp:send(Socket,io:format("hello joe~n")),
			%% read reply
			do_recv(Socket),
			%% I'm done.
			gen_tcp:close(Socket);
		Any ->
			io:format("Error = ~p~n",[Any]),
			error
	end.

do_recv(Socket) ->
    case gen_tcp:recv(Socket, 0) of
        {ok, B} ->
            io:format("reply tuple:~p~n",[B]);
	X -> 
	    io:format("reply atom:~p~n",[X])
    end.
    
%%    	wait_reply(X) ->
%% 	    receive
%% 	        X ->
%% 	            {value, X}
%% 	    after 100000 ->
%% 	            timeout
%% 	    end.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the erlang-questions mailing list