Skip to content

Primitive example of creating a DB-backed, realtime chat in Snap framework

Notifications You must be signed in to change notification settings

DennisMcWherter/snap-webchat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Realtime Chat (WebSockets) with Snap

This is an example of creating a realtime chat server using WebSockets with the snap framework. This is accompanied by a blog post that you can read for some basic guidance. It is intended simply as an example and is NOT intended for production use. There are very obvious performance and security concerns with this code. First of all, user input is not santized (i.e. clients may send malicious Javascript directly through chat) and the threading model is far from ideal.

I was learning some of these frameworks as I wrote this code, so it may not be the absolute best way (but, is there ever really such a thing?) to operate within the model provided by the frameworks, but you can certainly use this as a starting point for determing how things are to be done.

Building

To build and run this code, first create a table called "chat" in your PostgreSQL database. Then load the schema located in "bootstrap" into this table. From there, run the following commands:

cabal sandbox init
cabal install --dependencies-only
cabal run

Navigating

All functionality is located at the /chat endpoint. This endpoint is protected by the auth system, so you must first create an account and login. After having done this, try visiting

http://localhost:8000/chat

Similarly, after you have chatted for a little bit of time, you can visit http://localhost:8000/chat/last to see a history of your last 50 messages (note: all messages are still in the DB, but this endpoint only displays 50).

About

Primitive example of creating a DB-backed, realtime chat in Snap framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published