addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1linklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Hoodlums Message Board › Homework: WebSockets app

Homework: WebSockets app

Peter M.
Group Organizer
London, GB
Post #: 33
Thanks to all who attended tonight's meetup, we have a WebSockets Chat server. It is a little simple, but it works fine. This month's homework is to write a more sophisticated WebSockets app. You can extend the Chat server or come up with something completely different - time for some creativity.

The code from this evening's session is here­.

Neil B
user 13347289
London, GB
Post #: 2
Some resources for this websockets project:

  • A good HTML5 presentation which includes a simple websockets browser client, and a statement of the bare-minimum code for same. You probably need to view that in chrome.
    (The rest of the presentation is also worth a look, if you haven't looked at browser technology for a while.)

  • When developing an in-browser client, note that chrome has a built-in set of developer tools including a great javascript console and debugger. Tools: Javascript Console

  • A simple public hosted websockets echo server (For when you don't trust your own!): ws:// (remove whitespace)

  • Websocket protocol (Feb 8 2011):
    I'm guessing that at least the handshake stuff here may be changing a lot, due to the recent security issues. We'll hopefully be insulated by the websockets module.
  • Websockets API for the browser. Lists onopen(), onmessage(), onerror(), etc.

    As Peter already sent out, haskell docs for:
  • Websockets module
  • Sockets (accept)
  • Threads (forkIO)
  • Chan

    Finally, if you're new to haskell and or writing server components, you might like this:
  • tcp server tutorial
    It's written with haskell newbies in mind. You'll notice that there's not so much difference between the websockets server and the example this tutorial works up.

Thanks to Peter and everyone else for a great meetup.
A former member
Post #: 1

I'm having some problems trying to install network-websocket

It seems to be to do with the definition of Request clashing with Request in Network.HTTP (?)

> matt@mattg:~/haskells$ sudo cabal install network-websocket
> Resolving dependencies...
>Configuring network-websocket-0.3...
> Preprocessing library network-websocket-0.3...
> Preprocessing executables for network-websocket-0.3...
> Building network-websocket-0.3...
> [1 of 1] Compiling Network.Websocket ( Network/Websocket.hs, dist/build/Network/Websocket.o )

> Network/Websocket.hs:23:13:
> Duplicate instance declarations:
> instance Show Request -- Defined at Network/Websocket.hs:23:13-24
> instance Show Request -- Defined in Network.Web.HTTP
> cabal: Error: some packages failed to install:
> network-websocket-0.3 failed during the building phase. The exception was:
> ExitFailure 1

I get the same thing trying to install network-websocket-0.2

Any ideas how to proceed?

Peter M.
Group Organizer
London, GB
Post #: 34
Hi Matt

network-websocket isn't the package we used. It was websockets. Try that one.

Neil B
user 13347289
London, GB
Post #: 4
I thought I'd share a potential bug in websockets library so that it doesn't cause anyone else to waste time.

(Update: It's fixed in 0.3)

You may get connection attempts quietly rejected, with only the following sort of error logged by the server:
HsInvalidHeaderKey "Cookie: whateverkey=whatevervalue\r"

The websockets library should not be rejecting connections on account of cookie header(s).

Workaround: clear your browser's cookies for the domain the server is at (e.g. localhost).

I've sent a bug report to the library author.
Neil B
user 13347289
London, GB
Post #: 5
Hi all, here's my websockets homework submission.

Some say it is a lot like the game sold as "Pictionary". It's a web-based game where you have to draw a picture and others in your team observe the drawing and have to guess what it is.

PLAY here
(Google-chrome only, sorry.)

(There's no AI, sorry, so chances are you'll have to launch a few clients to test it out. Also, bear in mind that drawing is broadcast only to members of the artist's team.)

CODE is here

The server code is a car crash, forgive me. Nevertheless (and in testament to haskell) I've found it really easy to work with (up to this point). The pain has come from the html and javascript.

I'm at the stage where I have pretty much all the functionality I want and (time permitting) I will start trying to abstract what's going on, so I welcome suggestions for haskell and FP patterns which will help me. It's nice to be nearly feature complete with a naive code base, because the diffs of the subsequent refactorings may be informative to the other beginners in the group.

I think the most obvious candidate for overhaul is the dispatcher loop in which every path sees one or more modifications of the GameState (which includes the teams, the player names, the word list, as well as the state of play). I understand the state monad is a good match here (transformed so IO can be done, too). Don Stewart's irc bot tutorial looks like it will be a good guide in this as it does something very similar.

Also, there's no explicit state machine, which makes it harder to focus on the transitions between game states (AwaitingPlayers -> ReadyToPlay, etc). I haven't decided how to address that yet.

In-progress wild refactorings may appear in a branch other than master. For instance, on this branch you can see where I got to with writing a first handler under StateT GameState IO. Original version is here.

Pradeep R.
user 12595762
London, GB
Post #: 2
This is a work in progress homework submission for a game of fourfours.

Read more here -­

I attempted too many concepts which soon exhausted all my time..


* Parsec (in progress)
* Shared gamestate using MVar (which works)
* JSON response (works)

and spent an insane amount of time trying out different data structures and still ended up being unhappy about it.

Hopefully I will keep working on this and submit it fully working.

Powered by mvnForum

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy