我试图使用tcp套接字发送元组,我使用gen_tcp:send(Socket,{elem1,elem2})但我收到此错误,"输出端口上的错误值&t; tcp_inet' "任何人都可以告诉我如何通过套接字发送元组?
感谢您的回复。
答案 0 :(得分:1)
第二个参数必须是数据包:
Packet = string() | binary() | HttpPacket
HttpPacket = HttpRequest
| HttpResponse
| HttpHeader
| http_eoh
| HttpError
HttpRequest = {http_request, HttpMethod, HttpUri, HttpVersion}
HttpResponse =
{http_response, HttpVersion, integer(), HttpString}
HttpHeader =
{http_header,
integer(),
HttpField,
Reserved :: term(),
Value :: HttpString}
...
在你的情况下{elem1,elem2}
确实匹配任何这些类型,你就会收到错误。发送任意术语的常用方法是首先序列化它:term_to_binary(YourTerm)
并在收到后对其进行反序列化:binary_to_term(ReceivedBinary)