Note that there are some explanatory texts on larger screens.

plurals
  1. POSequencing Events Over Network (Networked Turn-Based Game)
    primarykey
    data
    text
    <p>I'm fairly new to haskell networking (and peer to peer communication in general) and was looking to work on a player-to-player networked hangman game, similar to the popular "hanging with friends". After following a few tutorials including haskell.org's "Implement a chat server", I was able to sucessfully create a server and connect socket to the socket, bouncing message back and fourth.</p> <p>I also have a hangman client which plays as expected when given a predetermined input.</p> <p>However, I'm running into issues sequencing events between the connected clients. Because reading and writing to the socket channel occur on separate threads (due to the blocking nature of readChan and writeChan), I'm unsure of how to sequence actions between remote terminals. I know what I want, just not how to get there:</p> <ol> <li>Once a second user has connected, call the "send" function which prompts them for an input word for the first player</li> <li>Player 1 recieves this word via the "recieve" function and, provided it's not a command keyword (Join, quit, outcome), run the hangman game with the supplied word. In the mean time, player 2's screen blocks, waiting on player 1 to finish.</li> <li>Player 1 finishes. His result is recorded, and then the "send" function is called for him, prompting him for an input to play the game with.</li> <li>Repeat 2-3 until a player quits.</li> </ol> <p>I've gone about this a couple ways. One of my more successful ways was via a blocking semaphore. I've thought to use an MVar with the turn of the "controlling" player. It runs correctly on the first turn, but degrades to gibberish thereafter. The concept of a semaphore within a channel (which is essentially an MVar in the way it too blocks) is really messing with my head. Since it does indeed block, its proving hard to debug as well.</p> <p>I'm a little shaky on my knowledge of semaphores. Does the way I'm going about doing this even make sense?</p> <p>The code can be found in a bitbucket repository. Here are the steps needed to get the correct code/branch:</p> <pre><code>git clone git@bitbucket.org:ndisidore/haskell-hangman.git git checkout block-sem </code></pre> <p>or <a href="https://bitbucket.org/ndisidore/haskell-hangman/src/7877047bdf34" rel="nofollow">view it online here</a>.</p> <p>To run: <code>runhaskell NetInterface.hs</code></p> <p>This creates a socket listening on port 3468</p> <p>To connect as a client/player, open a seperate terminal and run "telnet localhost 3468". This needs to be done twice, once for each player.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload