I am new to the haskell network (and generally communicate with colleagues) and have been looking for work on a game game in a game game similar to the popular “hanging out with friends”. After several tutorials, including haskell.org "Deploying the Chat Server", I was able to successfully create the server and connect the socket to the socket, scan the message back and the fourth.
I also have an executioner client that plays as expected with a given input.
However, I encounter issues related to events between connected clients. Since reading and writing on the socket occurs in separate threads (due to the nature of the readChan and writeChan locks), I am not sure how to perform the sequence of actions between the remote terminals. I know what I want, just not how to get there:
- Once the second user has connected, call the send function, which requests them for the input word for the first player.
- Player 1 receives this word through the “get” function and, if it is not a team keyword (Join, quit, result), start the executioner’s game with the provided word. At the same time, player screen 2 is locked, waiting for player 1 to finish.
- Player 1 ends. His result is recorded, and then the "send" function is called to him, offering him input for the game.
- Repeat 2-3 until the player leaves.
I did a couple of ways. One of my more successful ways was through a blocking semaphore. I thought to use MVar with a turn of the "control" player. It works correctly on the first turn, but then collapses to gibberish. The concept of a semaphore inside a channel (which is essentially an MVar in how it is too blocked) is really messing with my head. Since it really blocks, it is also difficult to debug.
I understand my semaphores a little precariously. Is the way I do this even make sense?
The code can be found in the bitbucket repository. Here are the steps required to get the correct code / branch:
git clone git@bitbucket.org :ndisidore/haskell-hangman.git git checkout block-sem
or view it here .
To run: runhaskell NetInterface.hs
This creates a socket listening on port 3468
To connect as a client / player, open a separate terminal and run "telnet localhost 3468". This must be done twice, once for each player.
Thanks in advance.
Dizzy source share