Skip to content

Commit

Permalink
Add instructions to run the server
Browse files Browse the repository at this point in the history
  • Loading branch information
randilt committed Jan 8, 2025
1 parent 72f7a96 commit 1546bad
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions examples/tcp-chat-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# TCP Chat Server

[![Star on Github](https://img.shields.io/badge/-Star%20on%20Github-blue?style=social&logo=github)](https://github.com/ballerina-platform/module-ballerina-tcp)

## Overview

A simple TCP chat server implementation in Ballerina that allows multiple clients to connect and exchange messages. Each message is broadcast to all connected clients with a sequential message number.

## Features

- Supports multiple concurrent client connections
- Broadcasts messages to all connected clients
- Sequential message numbering
- Handles client disconnections gracefully
- Welcome message for new clients

## Run the Server

```sh
# Start the server
$ bal run
```

## Connect as Client

You can connect using either telnet or netcat:

```sh
# Using telnet
$ telnet localhost 3000

# Using netcat
$ nc localhost 3000
```

## Testing

1. Open multiple terminal windows
2. Start the server in one terminal
3. Connect multiple clients using telnet/netcat in other terminals
4. Type messages in any client terminal and press Enter
5. Observe the broadcast messages in all client terminals

Each message will be prefixed with a sequential number and broadcast to all connected clients.

## Implementation Details

The server uses Ballerina's TCP module to:

- Listen for incoming connections on port 3000
- Maintain a map of connected clients
- Buffer incoming messages until newline
- Broadcast messages to all connected clients
- Handle client disconnections

0 comments on commit 1546bad

Please sign in to comment.