Bad value on output port 'tcp_inet'
Logan, Martin
Martin.Logan@REDACTED
Mon Aug 14 16:49:55 CEST 2006
You are using io:format to send the atom 'ok' over the wire. io:format
writes to stdout. The docs for gen_tcp:send/2 indicate that it accepts
the following payload type Packet = [char()] | binary(). Atom is not
among them. Try just firing off a string and see if it fixes your
problem.
Cheers,
Martin
-----Original Message-----
From: owner-erlang-questions@REDACTED
[mailto:owner-erlang-questions@REDACTED] On Behalf Of Jeff Crane
Sent: Sunday, August 13, 2006 3:29 PM
To: erlang-questions@REDACTED
Subject: Bad value on output port 'tcp_inet'
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