Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception: connect: does not exist (Connection refused) when trying to connect to TCP socket in Haskell

Context

I was following the tutorial on writing a TCP server last week in Real World Haskell. Everything went well and I had the final version of it working and was able to send messages between the TCP client and server.

Then, I wanted to write my own TCP server for a small TicTacToe game that I coded. I started out writing the server and client and played around with it a bit, it worked so far that the server was able to accept connections, but there was no real interaction yet.

Now it gets a bit awkward, because after I turned my Mac off and tried to reboot it again, it wouldn't boot any more. I fiddled around all Friday to do a backup from Single User Mode and reinstalled Mac OS. After a successful reinstallation, all my data was still there, so I didn't need the backup after all.

Anyway, today I am turning back to my TicTacToe-server but it doesn't work any more. Or, at least the client can't connect to it any more.

TL;DR

I wrote a TCP server for a TicTacToe game inspired by the tutorial in Real World Haskell but am getting a *** Exception: connect: does not exist (Connection refused) error when trying to connect to the server. The same happens with the vanilla code from the mentioned tutorial.

Note that I can still connect to the servers using telnet. I'm pretty sure the issue isn't with the code but rather on system level as the same code was working before I had the trouble with my machine (see above) and I am still using the identical code from the tutorial in RWH.

like image 212
nburk Avatar asked Nov 23 '15 15:11

nburk


1 Answers

Okay, the problem can be solved by connecting to 127.0.0.1 instead of localhost. Apparently some bindings were changed when my system broke down and got reinstalled, so ghc doesn't know how to resolve localhost (or something like that....)

like image 53
nburk Avatar answered Nov 11 '22 10:11

nburk