Czy jest zaimplementowany Klient WebSocket for.NET? [zamknięte]

Chciałbym używać WebSockets w moim Windows Forms lub WPF-application. Czy istnieje. Net-control, który obsługuje WebSockets zaimplementowane już? Czy jest jakiś projekt open source rozpoczęty o tym?

Rozwiązanie open source dla Klienta Java obsługującego WebSockets również może mi pomóc.

Author: semirturgay, 2010-01-14

11 answers

Teraz SuperWebSocket zawiera również implementację klienta WebSocket Strona Główna Projektu SuperWebSocket

Inne implementacje klienta. NET to:

 20
Author: Kerry Jiang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-28 17:21:13

Oto szybki pierwszy krok przy przenoszeniu kodu Javy do C#. Nie obsługuje trybu SSL i został bardzo lekko przetestowany, ale to dopiero początek.

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class WebSocket
{
    private Uri mUrl;
    private TcpClient mClient;
    private NetworkStream mStream;
    private bool mHandshakeComplete;
    private Dictionary<string, string> mHeaders;

    public WebSocket(Uri url)
    {
        mUrl = url;

        string protocol = mUrl.Scheme;
        if (!protocol.Equals("ws") && !protocol.Equals("wss"))
            throw new ArgumentException("Unsupported protocol: " + protocol);
    }

    public void SetHeaders(Dictionary<string, string> headers)
    {
        mHeaders = headers;
    }

    public void Connect()
    {
        string host = mUrl.DnsSafeHost;
        string path = mUrl.PathAndQuery;
        string origin = "http://" + host;

        mClient = CreateSocket(mUrl);
        mStream = mClient.GetStream();

        int port = ((IPEndPoint)mClient.Client.RemoteEndPoint).Port;
        if (port != 80)
            host = host + ":" + port;

        StringBuilder extraHeaders = new StringBuilder();
        if (mHeaders != null)
        {
            foreach (KeyValuePair<string, string> header in mHeaders)
                extraHeaders.Append(header.Key + ": " + header.Value + "\r\n");
        }

        string request = "GET " + path + " HTTP/1.1\r\n" +
                         "Upgrade: WebSocket\r\n" +
                         "Connection: Upgrade\r\n" +
                         "Host: " + host + "\r\n" +
                         "Origin: " + origin + "\r\n" +
                         extraHeaders.ToString() + "\r\n";
        byte[] sendBuffer = Encoding.UTF8.GetBytes(request);

        mStream.Write(sendBuffer, 0, sendBuffer.Length);

        StreamReader reader = new StreamReader(mStream);
        {
            string header = reader.ReadLine();
            if (!header.Equals("HTTP/1.1 101 Web Socket Protocol Handshake"))
                throw new IOException("Invalid handshake response");

            header = reader.ReadLine();
            if (!header.Equals("Upgrade: WebSocket"))
                throw new IOException("Invalid handshake response");

            header = reader.ReadLine();
            if (!header.Equals("Connection: Upgrade"))
                throw new IOException("Invalid handshake response");
        }

        mHandshakeComplete = true;
    }

    public void Send(string str)
    {
        if (!mHandshakeComplete)
            throw new InvalidOperationException("Handshake not complete");

        byte[] sendBuffer = Encoding.UTF8.GetBytes(str);

        mStream.WriteByte(0x00);
        mStream.Write(sendBuffer, 0, sendBuffer.Length);
        mStream.WriteByte(0xff);
        mStream.Flush();
    }

    public string Recv()
    {
        if (!mHandshakeComplete)
            throw new InvalidOperationException("Handshake not complete");

        StringBuilder recvBuffer = new StringBuilder();

        BinaryReader reader = new BinaryReader(mStream);
        byte b = reader.ReadByte();
        if ((b & 0x80) == 0x80)
        {
            // Skip data frame
            int len = 0;
            do
            {
                b = (byte)(reader.ReadByte() & 0x7f);
                len += b * 128;
            } while ((b & 0x80) != 0x80);

            for (int i = 0; i < len; i++)
                reader.ReadByte();
        }

        while (true)
        {
            b = reader.ReadByte();
            if (b == 0xff)
                break;

            recvBuffer.Append(b);           
        }

        return recvBuffer.ToString();
    }

    public void Close()
    {
        mStream.Dispose();
        mClient.Close();
        mStream = null;
        mClient = null;
    }

    private static TcpClient CreateSocket(Uri url)
    {
        string scheme = url.Scheme;
        string host = url.DnsSafeHost;

        int port = url.Port;
        if (port <= 0)
        {
            if (scheme.Equals("wss"))
                port = 443;
            else if (scheme.Equals("ws"))
                port = 80;
            else
                throw new ArgumentException("Unsupported scheme");
        }

        if (scheme.Equals("wss"))
            throw new NotImplementedException("SSL support not implemented yet");
        else
            return new TcpClient(host, port);
    }
}
 24
Author: jhurliman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-04-06 20:01:03

Wsparcie dla WebSockets jest nadchodzi. NET 4.5 . Link ten zawiera również przykład użycia klasy System.Net.WebSocket.WebSocket .

 11
Author: Stephen Rudolph,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-23 20:15:28

Kaazing.com zapewnij bibliotekę klienta. NET, która może uzyskać dostęp do websockets. Mają samouczki online na Checklist: Build Microsoft. NET JMS Clients and Checklist: Build Microsoft. NET AMQP Clients

Istnieje projekt Java Websocket Client na GitHubie.

 7
Author: Robert Christie,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-22 22:05:09

Istnieje implementacja klienta: http://websocket4net.codeplex.com/!

 5
Author: Kerry Jiang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-09 02:32:54

Inny wybór: XSockets.Net , posiada zaimplementowany serwer i klienta.

Można zainstalować serwer przez:

PM> Install-Package XSockets

Lub zainstaluj klienta przez:

PM> Install-Package XSockets.Client

Aktualna wersja to: 3.0.4

 4
Author: sendreams,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-17 05:44:17

Oto lista pakietów websocket NuGet obsługiwanych przez. Net

Websocket pakages .

Wolę podążać za klientami

  1. Alchemy websocket
  2. SocketIO
 3
Author: shivakumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-17 18:30:34

To dość prosty protokół. jest tu implementacja Javy , która nie powinna być zbyt trudna do przetłumaczenia na c#. jeśli to zrobię, wyślę to tutaj...

 1
Author: billywhizz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-02-25 05:36:53

Niedawno Interoperability Bridges and Labs Center opublikowało prototypową implementację (w kodzie zarządzanym) dwóch wersji specyfikacji protokołu WebSockets:

projekt-hixie-thewebsocketprotocol-75 i projekt-hixie-thewebsocketprotocol-76

Prototyp można znaleźć w HTML5 Labs. Umieściłem ten wpis na blogu wszystkie informacje, które znalazłem (do tej pory) i fragmenty kodu o tym, jak można to zrobić za pomocą WCF.

 1
Author: Nikos Baxevanis,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-12-25 19:41:51

Jeśli chcesz coś nieco lżejszego, sprawdź serwer C#, który wydaliśmy razem ze znajomym: https://github.com/Olivine-Labs/Alchemy-Websockets

Obsługuje vanilla websockets, jak również Flash websockets. Został stworzony z myślą o naszej grze online z naciskiem na skalowalność i wydajność.

 1
Author: Jack Lawson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-24 20:24:40
 0
Author: Rushino,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-11 23:13:28