This project is a simple chat server implemented in Go. It allows multiple clients to connect, choose nicknames, join chat rooms, send messages, and see available rooms.
- Nicknames: Clients can set their nicknames.
- Join Rooms: Clients can join existing chat rooms or create new ones.
- Message Rooms: Clients can send messages to all members of a room.
- List Rooms: Clients can list all available rooms.
- Quit: Clients can quit the server gracefully.
- Go (version 1.16+)
-
Clone the repository:
git clone https://github.com/seniorLikeToCode/GoSocketChat.git cd GoSocketChat
-
Build the server:
go build -o main.go
-
Run the server:
./main
The server will start and listen for connections on port 5000.
You can use telnet
or netcat
to connect to the server:
telnet localhost 5000
or
nc localhost 5000
Once connected, you can use the following commands:
-
/nick NAME: Set your nickname.
/nick mynickname
-
/join ROOM_NAME: Join a room or create a new one if it doesn't exist.
/join room1
-
/msg MSG: Send a message to the current room.
/msg Hello everyone!
-
/rooms: List all available rooms.
/rooms
-
/quit: Quit the server.
/quit
telnet localhost 5000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
/nick Alice
all right, I will call you Alice
/join room1
Welcome to room1
/msg Hello, room1!
Alice: Hello, room1!
/rooms
available rooms: room1
/quit
sad to see you go :(
Connection closed by foreign host.
The server logs all connections, disconnections, and errors to the standard output.