gen_tcp stands for 'Generic TCP' and is a module in Erlang that provides functions for TCP/IP communication.
Questions tagged [gen-tcp]
80 questions
1
vote
0 answers
gen_tcp based server/client persistent and encrypted(ssl/tls) tcp connection in erlang
I have an erlang based messaging application where I am using gen_tcp module to communicate between client and server over tcp. the current implementation is not encrypted and thus secure also. So now i would like to use ssl/tls to secure the…

Neel
- 429
- 7
- 17
1
vote
1 answer
How can I listen multiple ports via Elixir?
I'd like to listen 2 ports via Elixir. I managed to listen the ports, though. However, I can't get data from second port.
def accept() do
{:ok, socket} = :gen_tcp.listen(7777, [:binary, packet: 0, active: false, reuseaddr: true])
{:ok,…

user10186746
- 11
- 1
1
vote
0 answers
Elixir - How can I connect to a TCP? :gen_tcp is giving me trouble
I have Vowpal Wabbit server running at a certain IP and on a certain port. I can interact with it from the command line as follows:
echo "|c country_US" | nc 10.228.14.116 26542
0.512143 <-- this is the response
On the other hand, if I don't…

tadasajon
- 14,276
- 29
- 92
- 144
1
vote
3 answers
Erlang missing messages
I'm running the following code with dbg:p(client, r):
-module(client).
-export([start/0, start/2, send/1, net_client/1]).
start() ->
start("localhost", 7000).
start(Host, Port) ->
io:format("Client connecting to ~p:~p.~n", [Host, Port]),
…

nmichaels
- 49,466
- 12
- 107
- 135
1
vote
1 answer
CLOSED error when establishing lots of connections with gen_tcp in parallel (Bug?)
When trying to establish a largeish number of TCP connections in parallel I observe some weird behavior I consider a potential bug in gen_tcp.
The scenario is a server listening on a port with multiple concurrent acceptors. From a client I…

jvf
- 866
- 7
- 13
1
vote
1 answer
using {packet, N} in gen_tcp and how to receive data in a c++ program
I have worked when both the ends of communication were based on erlang and documentation makes it clear that using {packet, N} appends a header with the size of the message and gen_tcp:recv/2 removes the header when receiving. This is pretty…

sad
- 820
- 1
- 9
- 16
1
vote
0 answers
receiving data sent using gen_tcp:send/2
I have an erlang client which is sending me data using gen_tcp:send/2
Specifically, it is sending me like this,
gen_tcp:send(Socket, <>)
I have a c++ based, tcp server, that receives the message. If the client could…

listen
- 217
- 2
- 7
1
vote
1 answer
sending message over a socket using gen_tcp:send/2
How to send a message of the form [Integer, String] in erlang using gen_tcp.
Eg: I am looking to send messages of the form [25, "Hello"] or [50, "Hi"] over a socket using gen_tcp:send/2.
I tried to do [ID | Msg] but that doesn't help.
Thanks

listen
- 217
- 2
- 7
1
vote
1 answer
tcp server and client interaction
I have a tcp server(echo server) accepting connections. I have a client which when given a parameter N, creates those many processes trying to connect with the tcp listener. I am able to connect to those sockets but I can see many sockets being…

listen
- 217
- 2
- 7
1
vote
1 answer
Client closed after sending a message, why gen_tcp with opts {active, false} accept twice
I just do a testing with gen_tcp. One simple echo server, and one client.
But client started and closed, server accept two connection, and one is ok, the other is bad.
Any issue of my demo script, and how to explain…

linbo
- 2,393
- 3
- 22
- 45
1
vote
1 answer
Erlang gen_tcp:recv http_request abs_path
I'm writing code in Erlang that accepts HTTP requests. I have working code which is shown below.
The problem I have is that I'm unsure about the returned result of gen_tcp:recv.
I create a listening socket and accept sockets using
{ok,…

Christophe De Troyer
- 2,852
- 3
- 30
- 47
1
vote
1 answer
Erlang gen_tcp:recv socket closing
I am working in project with websockets and MQTT. Websocket server receives 4 messages from mqtt and I made it loop to receive any other messages. However, if there are no messages, Encoded_fixed_header = gen_tcp:recv(Socket, 0) gives an error…

Rad1
- 185
- 1
- 4
- 17
1
vote
1 answer
How to deal with erroneous length headers for packets in TCP stream in Erlang?
I'm receiving messages over TCP in Erlang using gen_tcp. The stream is divided into packets by using a 4 byte length header, as specified by the {packet, 4} option. This is how I call gen_tcp:listen/2:
gen_tcp:listen(Port, [binary, inet, {active,…

Max
- 189
- 7
1
vote
2 answers
Erlang: send file and filename
I'm interesting to send a file and it's filename.
Server's options:
-define(TCP_OPTIONS_SERVER, [binary, {packet, 0}, {active, false}]).
That's the receiver loop:
file_receiver_loop(Socket,Bs)->
case gen_tcp:recv(Socket, 0) of
{ok, B} ->
…

Giovanni C
- 111
- 8
1
vote
1 answer
Erlang gen_tcp delaying send
I have the below code as part of an Erlang web server for many long-lived concurrent connections.
SockOpts = [
binary,
{active, false},
{packet, http_bin},
{reuseaddr, true},
{packet_size, 16384},
{recbuf, 16384},
…

Max
- 2,760
- 1
- 28
- 47