Paulo Sousa
Paulo Sousa

Reputation: 75

Send tuple through tcp socket in Erlang

I'm trying to send a tuple using a tcp socket, I'm using gen_tcp:send(Socket, {elem1,elem2}) but I'm receiving this error, "bad value on output port 'tcp_inet' " can anyone tell me how can I send a tuple through a socket?

Thanks for your replies.

Upvotes: 1

Views: 648

Answers (1)

Pascal
Pascal

Reputation: 14042

The second argument must be a Packet:

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}
...

in your case {elem1,elem2} does match any of these type and you get the error. The usual way to send an arbitrary term is to serialize it first:term_to_binary(YourTerm)

and deserialize it when you receive it : binary_to_term(ReceivedBinary)

Upvotes: 1

Related Questions