zoukankan      html  css  js  c++  java
  • SocketIO4Net.Client

    Project Description

    SocketIO4Net.Client

    Update as of 11/02/2013

     A develop branch is up at https://github.com/jstott/socketio4net/tree/develop for anyone looking to take an early peek.  Xhr-polling and websockets are working from the C# client.  Thank to the efforts from one of our users Nick, this feature is just about there!

    Of particular interest, I'm looking for feedback on the .net 40 assembly types (client, PCL etc...) most interested in.  The plan is to release a both .net v4.0 & v4.5, using native .net websockets in v4.5 vs websocket4net currenlty in v4.0.

    SocketI04net v4.0 is now leveraging the Microsoft.BCL.Async library (includes Microsoft.BCL.Build, Http packs) - please let me know if that create any additional issues.

    Nuget packages are not available (yet), but after some additional testing and release notes will create a pre-release version for the latest code.

    Please continue to leave discussions here, and if you have/see any issues with the latest develop code on github, please log there.

    Jim

    NuGet updated to v06.26

    Project Description

    SocketIO4Net.Client provides a .NET 4.0 C# client for Socket.IO.  It provides an overall interface similar to the client JavaScript experience, leveraging the WebSocket4Net project for an underlying websocket implementation.

    My goal for this project is a simple & familiar experience for .net clients.  You know you want your .Net app to join in some of the fun, right?  Besides, all the cool kids are using Nodejs and Socket.IO these days anyway, give it a whirl.

    This resulting signature is very similar to the socket.io javascript counterpart:

    node.js / JavaScript client

    socket.on('news', function (data) {
        console.log(data);
    });

    C# .net client

    socket.On("news", (data) =>    {
        Console.WriteLine(data);
    });

    The all important - Sample / Demo code snippet 

    Client socket;
    public void Execute()
    {
        Console.WriteLine("Starting TestSocketIOClient Example...");
    
        socket = new Client("http://127.0.0.1:3000/"); // url to nodejs 
        socket.Opened += SocketOpened;
        socket.Message += SocketMessage;
        socket.SocketConnectionClosed += SocketConnectionClosed;
        socket.Error += SocketError;
                
        // register for 'connect' event with io server
        socket.On("connect", (fn) =>
        {
            Console.WriteLine("
    Connected event...
    ");
            Console.WriteLine("Emit Part object");
    
            // emit Json Serializable object, anonymous types, or strings
            Part newPart = new Part() 
            { PartNumber = "K4P2G324EC", Code = "DDR2", Level = 1 };
            socket.Emit("partInfo", newPart);
        });
    
        // register for 'update' events - message is a json 'Part' object
        socket.On("update", (data) =>
        {
            Console.WriteLine("recv [socket].[update] event");
            //Console.WriteLine("  raw message:      {0}", data.RawMessage);
            //Console.WriteLine("  string message:   {0}", data.MessageText);
            //Console.WriteLine("  json data string: {0}", data.Json.ToJsonString());
            //Console.WriteLine("  json raw:         {0}", data.Json.Args[0]);
                    
            // cast message as Part - use type cast helper
            Part part = data.Json.GetFirstArgAs<Part>();
            Console.WriteLine(" Part Level:   {0}
    ", part.Level);
        });
    
        // make the socket.io connection
        socket.Connect();
    }

    Getting Started

    Two ways to get started:

    1. Download source code, compile, and run the included Test & Sample code and have a look around.
    2. Install via Nuget – run the following command in the Package Manager Console >  Install-Package SocketIO4Net.Client

    See the Documentation section for further details.

  • 相关阅读:
    PowerDesigner 找不到Identity列的解决方法
    C# DataTable 和List之间相互转换的方法
    解决Win8无法升级.NET Framework 3.5.1 提示错误0x800F0906
    C#虚方法和抽象方法区别
    VS自带WCF测试客户端
    asp.net读取Excel数据
    输出用户的IP地址,并且判断用户的IP地址是否在192.168.1.100 --- 192.168.1.150之间
    验证电子邮箱正则表达式
    用PHP实现冒泡排序将数组$a=array()按照从小到大的方式排序
    打开a.txt文件在文件中最前面加上hello
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/3490534.html
Copyright © 2011-2022 走看看