GithubHelp home page GithubHelp logo

renqiancheng / csharp-websocket-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mazymodz/csharp-websocket-server

0.0 0.0 0.0 104 KB

A simple, user-friendly C# WebSocket Server

License: MIT License

C# 98.21% HTML 1.79%

csharp-websocket-server's Introduction

C# WebSocket Server


Introduction

C# WebSocket Server is a easy and user-friendly Listen server for WebSocket clients written in Microsoft’s C# language. The code itself is located in 3 class files - Server.cs, Client.cs and Helpers.cs. A listen server is easily created by simply creating a new Server object. After the object is created, you will have to bind the events that the server object has where you choose what to do with the data.


Content

The system has three objects:

  • Server - The listen server object
  • Client - The object that represents a connected client
  • Helpers - Helper methods and data types for the above objects

Features

This system currently supports the following features:

  • Handle Client Connection
  • Handle Client Disconnection
  • Receive Client Message
  • Send Message to Client
  • Encode WebSocket Data Frame
  • Decode WebSocket Data Frame
  • Preform WebSocket Handshake

Listen server example

Here's an example of a simple console application listen server using the class:

// Console application entry point
static void Main(string[] args) 
{
    // Create a new websocket server
    Server server = new Server(new IPEndPoint(IPAdress.Parse(127.0.0.1), 80));

    // Bind the event for when a client connected
    server.OnClientConnected += (object sender, OnClientConnectedHandler e) =>
    {
        string clientGuid = e.GetClient().GetGuid();
        Console.WriteLine(“Client with guid {0} connected!, clientGuid);
    };

    // Bind the event for when a message is received
    server.OnMessageReceived += (object sender, OnMessageReceivedHandler e) =>
    {
        Console.WriteLine(“Message received: {0}, e.GetMessage());
    };
}


Copyright © 2017 - MazyModz. Created by Dennis Andersson. All rights reserved.

csharp-websocket-server's People

Contributors

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