<html theme="default-light" iconset="color"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body text="#000000">I have a pastebin clone that accepts content
over a socket
(<a class="moz-txt-link-freetext" href="https://github.com/m1dnight/exbin/blob/main/lib/exbin/socket.ex">https://github.com/m1dnight/exbin/blob/main/lib/exbin/socket.ex</a>). The
way you do it there is `echo "my content" | nc example.com 9999`. <br>
<br>
I do recall that getting it to work was a bit of fiddling with the
socket options..<br>
<br>
<span>Magnus Leone wrote on 11/12/2021 2:24 AM:</span><br>
<blockquote type="cite"
cite="mid:CABz=PzMrh10RSUKPmGdxYcX7pb59v2eajjEYdDxNxDUepvvzEw@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<div dir="ltr"><div>Hello,</div><div><br></div><div>I'm working on
making a very basic talk about networking, and eventually a webserver,
but I thought I'd start with the very basic parts; just a TCP echo
server. The thing is that the talk is not specifically about Erlang, I'm
just using that as I'm most familiar with it (and hey, if I get some
people interested, that's great). So I wanted the client side to be just
a regular shell.</div><div><br></div><div>Here is where my problem
comes in - I can't seem to get the server process to accept the incoming
connection when it comes from a shell. The code is pretty much straight
out of Joe's book and it works fine as long as the other side is also
an Erlang process. What I've tried so far:</div><div><br></div><div>>telnet
localhost 7777<br>Trying 127.0.0.1...<br>telnet: Unable to connect to
remote host: Connection refused<br></div><div><br></div><div>>netcat
localhost 7777</div><div>*no output*</div><div><br></div><div>Does
anyone know how I can use bash to connect to a TCP socket in this
scenario?</div><div><br></div><div>Cheers,</div><div>Magnus</div><div><br></div><div>start(Port)
-><br> {ok, ListenSocket} =<br> gen_tcp:listen(Port,
[list, {packet, 0},<br> {reuseaddr,
true},<br> {active, true}]),<br>
{ok, Socket} = gen_tcp:accept(ListenSocket),<br> ok =
gen_tcp:close(ListenSocket),<br> io:format("Server accepted
connection on port ~p~n", [Port]),<br> loop(Socket).<br><br>loop(Socket)
-><br> receive<br> {tcp, Socket, StringMsg} -><br>
io:format("Server received message: ~p~n", [StringMsg]),<br>
Reply = "Echo " ++ StringMsg,<br> io:format("Server
replying: ~p~n", [Reply]),<br> gen_tcp:send(Socket, Reply),<br>
loop(Socket);<br> {tcp_closed, Socket} -><br>
io:format("Server socket closed - shutting down...~n")<br> end.</div></div>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<div>Sent from <a href="https://www.postbox-inc.com"><span style="color:
rgb(0, 157, 247);">Postbox</span></a></div></div>
</body></html>