2009-11-24 65 views
3

使用以下代碼發送。該調用gen_tcp:發送調用返回{錯誤,EINVAL}但我想不通爲什麼...通過TCP發送Erlang中的二進制文件

-define(TCP_OPTIONS,[binary, {active, false}, {reuseaddr, true}]). 

client() -> 
    case gen_tcp:connect(to_Server(), 8080, ?TCP_OPTIONS) of 
    {error, Reason} -> 
     io:format("~p~n",[Reason]); 
    {ok,My_Socket} -> 
     Message = {"stuff", hello, "data"}, 
     B_Message = term_to_binary(Message), 
     OK = gen_tcp:send(My_Socket, {message,B_Message}), % error here 
     OK = gen_tcp:close(My_Socket) 
end. 

回答

13

您正在嘗試發送郵件{,B_Message},這是一個元組,但調用gen_tcp:送只接受字符列表或二進制文件作爲其第二個參數。您可能想要:

% ... 
OK = gen_tcp:send(My_Socket, B_Message), 
% ...