<div dir="ltr">Heh, I figured out why it didn't work. It was because the server was running in a PowerShell on Windows, whereas the client side was running in a WSL2 Linux shell on the same host. If I start both of them in either WSL2 or in PowerShell, then it works fine. Thanks for your help.<div><br></div><div>Cheers,</div><div>Magnus</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 12, 2021 at 9:48 AM Christophe De Troyer <<a href="mailto:christophe@call-cc.be">christophe@call-cc.be</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>I have a pastebin clone that accepts content
over a socket
(<a href="https://github.com/m1dnight/exbin/blob/main/lib/exbin/socket.ex" target="_blank">https://github.com/m1dnight/exbin/blob/main/lib/exbin/socket.ex</a>). The
way you do it there is `echo "my content" | nc <a href="http://example.com" target="_blank">example.com</a> 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">
<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>-- <br>
<div>Sent from <a href="https://www.postbox-inc.com" target="_blank"><span style="color:rgb(0,157,247)">Postbox</span></a></div></div>
</div>
</blockquote></div>