Skip to content

MazyModz/CSharp-WebSocket-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A simple, user-friendly C# WebSocket Server

Resources

License

Stars

Watchers

Forks

Packages

No packages published