Code Monkey home page Code Monkey logo

tcpchat's Introduction

TCP/IP Chat Application

Basic asynchronous TCP/IP chat app, developed live at https://www.youtube.com/playlist?list=PLIebvSMVr_dehKSoq6vuAW0BGEM6QnDlS

There is no such thing as a "simple" TCP/IP application, but this is pretty close. This repository is a minimal correct implementation.

Minimal Correct Implementation

Each socket connection is two unidirectional streams of bytes. A minimal correct implementation consists of:

  • Message framing, to translate the streams of bytes to streams of messages.
  • Error handling:
    • Always Be Reading - this lets you detect errors as quickly as possible.
    • Asynchronous APIs - so we don't need multiple threads per socket.
    • Close both streams for a connection at the same time - so that both sides can detect errors as long as data is still being transferred.
  • Keepalives, to detect the half-open scenario.

Overview of ChatApi Architecture

  • PipelineSocket - kind of like NetworkStream but using System.IO.Pipelines instead of Stream. PipelineSocket provides two unidirectional pipelines of bytes.
  • ChatConnection:
    • Serializes chat protocol messages to/from bytes. ChatConnection provides two unidirectional channels of messages.
    • Handles keepalives:
      • Periodically sends keepalive messages.
      • Ignores incoming keepalive messages.
    • Handles request/response logic:
      • Has a collection of outstanding requests.
      • Handles response messages by completing their matching request.

What's Missing

  • Security
    • Encryption. This protocol is a plain-text protocol.
    • Server/client authentication.
    • Misbehaving clients/servers. This app assumes correctly formed packets.
    • Denial of service. E.g., really large length prefixes, sending data too slowly, etc.
    • Reflection attacks. E.g., broadcast huge message at a high rate.
  • Higher-level state machine. E.g., when connection is lost, retry connection after some timeout.
    • Consider a Desired State pattern: the user indicates the desired state, and your application performs whatever connection and messages are necessary to achieve that state.

Resources

Tools

tcpchat's People

Contributors

stephencleary 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.