Skip to content

zhenruyan/sshroom4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSH Spring Chat Room

An SSH protocol-based chat room built with Spring Boot and Apache MINA SSHD, supporting anonymous users to chat in real-time via SSH connections.

Features

  • SSH Protocol Support: Users can connect directly via SSH clients
  • Anonymous Chat: No registration required, start chatting immediately
  • Virtual Threads: Based on JDK 21 virtual threads, supporting high-concurrency connections
  • Real-time Messages: Messages broadcast to all online users in real-time
  • Message History: New users can see recent chat history when joining
  • User Management: Display online user list and statistics
  • Command Support: Built-in chat commands

Tech Stack

  • JDK 21 - Virtual threads support
  • Spring Boot 3.2.1 - Application framework
  • Apache MINA SSHD 2.11.0 - SSH server implementation
  • Maven - Build tool

Quick Start

1. Requirements

  • JDK 21 or higher
  • Maven 3.6+

2. Build Project

mvn clean compile

3. Run Application

mvn spring-boot:run

Or build JAR and run:

mvn clean package
java -jar target/ssh-chatroom-1.0.0.jar

4. Connect to Chat Room

Use SSH client to connect to the chat room:

ssh -p 2222 localhost

Or connect to remote server:

ssh -p 2222 your-server-ip

Note:

  • Supports login with any username and password (anonymous mode)
  • Default port is 2222, configurable in application settings

Usage

After successful connection, you'll see the welcome interface. Supports the following operations:

Chat Commands

  • Direct text input - Send chat messages
  • /help - Show help information
  • /users - Show online user list
  • /stats - Show chat room statistics
  • /quit or /exit - Exit chat room

Example Conversation

╔══════════════════════════════════════════════════════════════╗
║                     SSH Chat Room                           ║
║                                                              ║
║  Welcome to SSH Chat Room!                                  ║
║  - Type messages to start chatting                          ║
║  - Type '/help' for help                                    ║
║  - Type '/users' to see online users                        ║
║  - Type '/quit' to exit chat room                           ║
║                                                              ║
║  Powered by JDK21 virtual threads for high performance!     ║
╚══════════════════════════════════════════════════════════════╝

Online users: 1 | Enter message: Hello everyone!
[14:30:25] Anonymous1: Hello everyone!
Online users: 2 | Enter message: /users

Online Users (2 users):
════════════════════════════════════════
• Anonymous1 (ID: 1) - /127.0.0.1:54321
• Anonymous2 (ID: 2) - /127.0.0.1:54322
════════════════════════════════════════

Configuration

Main configuration in src/main/resources/application.yml:

ssh:
  server:
    port: 2222                    # SSH server port
    host: 0.0.0.0                # Bind address
    max-connections: 100          # Maximum connections
    welcome-message: "Welcome to SSH Chat Room!"

logging:
  level:
    com.sshspring: DEBUG          # Log level

Architecture

Virtual Threads Support

The project fully utilizes JDK 21 virtual threads:

  • Each SSH connection uses an independent virtual thread
  • Message broadcasting uses virtual thread pool for concurrent sending
  • Supports thousands of concurrent connections without exhausting system resources

Core Components

  1. SshChatroomApplication - Spring Boot main application class
  2. SshServerConfig - SSH server configuration
  3. ChatRoomService - Chat room core service
  4. SshChatShellFactory - SSH Shell factory
  5. SshChatCommand - SSH command processor
  6. ChatUser - User model
  7. ChatMessage - Message model

Development

Project Structure

src/main/java/com/sshspring/
├── SshChatroomApplication.java     # Main application class
├── config/
│   └── SshServerConfig.java       # SSH server configuration
├── model/
│   ├── ChatUser.java              # User model
│   └── ChatMessage.java           # Message model
├── service/
│   └── ChatRoomService.java       # Chat room service
└── ssh/
    ├── SshChatShellFactory.java   # SSH Shell factory
    └── SshChatCommand.java         # SSH command processor

Extended Features

Can easily extend the following features:

  • User authentication and permission management
  • Private messaging
  • Chat room grouping
  • Message persistence
  • File transfer
  • Bot integration

License

MIT License

Contributing

Issues and Pull Requests are welcome!

Contact

For questions or suggestions, please create an Issue.

About

ssh chat room like springboot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages