Simple chatroom application written in Go
git clone https://github.com/moyuanhuang/gochat.git
cd gochat
make
- For server, type
./gochat server host:port
to start the server. If running the server locally, you can omit the host part. - For client, type
./gochat client host:port
to enter an existing chatroom. Then type your chat name(required) to start chatting with others. If running the client locally, you can omit the host part.
-
Currently the server can't handle the case when two clients have the same
UserName
. This is because inServer.handleBroadcast()
, I useUserName
to distinguish different clients. The solution is to useconn.RemoteAddr().String()
as the key of the map, however, this would require an extra map ofRemoteAddr -> UserName
in order to get the clients' name. It will require another map of ifUserName -> RemoteAddr
if we are to support mention(@) functionality(consider the case@dahuang hello
, how to direct this message to dahuang only). The current solution thus seems to be the most cost-efficient one. -
default port, don't bother user to decide it