Chat server written in Go.
Idea taken from https://web.archive.org/web/20111012115624/http://itasoftware.com/careers/work-at-ita/hiring-puzzles.html
Screen.Recording.2021-10-01.at.9.29.24.PM.mov
waddle [port]
- Go compiler.
- (Optional) Some program that sends data over a TCP socket. Any examples here will use
netcat
since it comes preinstalled on MacOS, most Linux distributions, and is available on Windows.
- Clone or download the repo.
cd
to its directory.- Compile and run with Go:
go run cmd/waddle/waddle.go [port]
. NOTE: Port is required.
This will start the server and listen on the given port. To connect to the server:
nc localhost [port]
Where port is the same port you used on the compile and run command. You should now be able to send and receive messages to/from the server.
go test ./internal/...
<CRLF> indicates the bytes "\r\n".
LOGIN <username><CRLF> - Login as given username.
JOIN #<chatroom><CRLF> - Create or join a chatroom. Chatrooms begin with '#'.
PART #<chatroom><CRLF> - Leave a chatroom. A user is able to join multiple chatrooms at once.
MSG #<chatroom> <message-text><CRLF> - Send a message to all users in a chatroom.
MSG <username> <message-text><CRLF> - Send a message directly to user.
LOGOUT<CRLF> - Log off and close connection to server.
Server responses:
OK<CRLF> - Indicates command was accepted.
ERROR <reason><CRLF> - Indicates an error has occured.
GOTROOMMSG <sender> #<chatroom> <message-text><CRLF> - When a message was sent to the room the user is in.
GOTUSERMSG <sender> <message-text><CRLF> - When a message was sent directy to the user.
Despite what the protocol section says, the current implementation does not actually check for <CRLF>
at the end of every request. Right now it only checks for a newline. The reason for this is to make it easier to test and play with using any program that sends data over a TCP socket, like netcat
.