Giter VIP home page Giter VIP logo

ktorwebsocketschat's Introduction

GitHub license

Kotlin Chat App

Support multi-clients chat together, and at the same, the LunLunBot will join the chat.

img_1.png

Architecture

  • Ktor + Netty to use server functionality without having to rely on an external app container.
  • Ktor WebSocket the main communication mechanism for the chat.
  • Arrow-kt the FP coding style for Kotlin.

Server

In charge of all the messages exchange for clients and the bridge to connect to the AI brain.

Main: /KtorWebsocketsChat/server/sre/main/kotlin/com/clluv/chat/server/Application.kt

Client

The chat client, also send some commands to the server to let others know the client is adding/leavning to the chat.

Main: /KtorWebsocketsChat/client/sre/main/kotlin/com/clluv/chat/client/ChatClient.kt

Commands

Clients can type /commads to list all supporting commands

/commands

Terms

WebSockets

Chat sessions are usually long-lived, with the client receiving messages from other participants over a long period of time.

Unlike regular HTTP requests, WebSocket connections can be kept open for a long time and have an easy interface for exchanging data between the client and server in the form of frames.

We can think frames as WebSocket messages which come in different types (text, binary, close, ping/pong).

Because Ktor provides high-level abstractions over the WebSocket protocol, we can concentrate on text and binary frames, and leave the handling of other frames to the framework.

Suspending Functions

Suspending functions are the center of everything coroutines.

A suspending function is simply a function that can be paused and resumed at a later time.

They can execute a long-running operation and wait for it to complete without blocking.

Companion Objects

An object declaration inside a class can be marked with the companion keyword.

Members of the companion object can be called simply by using the class name as the qualifier.

The name of the companion object can be omitted, in which case the name Companion will be used.

Class members can access the private members of the corresponding companion object.

Reference

ktorwebsocketschat's People

Contributors

chunglun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.