Skip to content

hjhome2000/socket.io-csharp-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C# Socket.IO client

A simple C# implementation of the Socket.IO client using WebSocket4Net.

DISCLAIMER: This is not a complete implementation of the Socket.IO client. There are lots of missing parts. Please feel free to submit a pull-request to add whatever feature is missing that you need.

Usage

Server

var io = require("socket.io").listen(3000);

io.sockets.on("connection", function (socket) {
   socket.on("data", function (data) {
      console.log("Client sent: " + data);
      
      if (data) {
         socket.emit("data", data.toUpperCase(), { length: data.length });
      }
   });
});

Start the server by running npm install then node index.js from the Example/Server directory.

Client

using System;
using SocketIO.Client;

namespace SimpleClient
{   
   class Example
   {
      static void Main()
      {
         var io = new SocketIOClient();
         
         var socket = io.Connect("http://localhost:3000/");

         socket.On("data", (args, callback) =>
         {
            Console.WriteLine("Server sent:");

            for (int i = 0; i < args.Length; i++)
            {
               Console.WriteLine("[" + i + "] => " + args[i]);
            }
         });
         
         string line;
         
         while ((line = Console.ReadLine()) != "q")
         {
            socket.Emit("data", line);
         }
      }
   }
}

Run the C# client and interact with the server by typing anything into the console.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published