Serwer WebSocket dla Delphi

TsgcWebSocketHTTPServer: wielowątkowy komponent serwera WebSocket i HTTP z obsługą IOCP/EPOLL, SSL/TLS, uwierzytelnianiem i serwowaniem plików statycznych.

TsgcWebSocketHTTPServer

Serwer HTTP + WebSocket obsługuje handshake wss://, rozgłasza wiadomości i zawiera wbudowane TLS, uwierzytelnianie, rejestrację w load balancerze oraz HTTP/2.

Klasa komponentu

TsgcWebSocketHTTPServer

Protokół

WebSocket — RFC 6455

Platformy

Windows, macOS, Linux, iOS, Android

Edycja

Professional / Enterprise

Upuść komponent, ustaw kilka właściwości i gotowe

Upuść TsgcWebSocketHTTPServer, ustaw Port i SSL, podłącz OnMessage i serwer działa.

uses
  sgcWebSocket, sgcWebSocket_Server, sgcWebSocket_Classes;

var
  WSServer: TsgcWebSocketHTTPServer;
begin
  WSServer := TsgcWebSocketHTTPServer.Create(nil);
  WSServer.Port := 80;

  WSServer.OnConnect       := WSServerConnect;
  WSServer.OnMessage       := WSServerMessage;
  WSServer.OnDisconnect    := WSServerDisconnect;
  WSServer.OnError         := WSServerError;
  WSServer.OnAuthentication := WSServerAuthentication;

  WSServer.Active := True;
end;

procedure TForm1.WSServerMessage(Connection: TsgcWSConnection;
  const Text: string);
begin
  // Broadcast to every connected client
  WSServer.WriteData(Text);
end;

procedure TForm1.WSServerAuthentication(Connection: TsgcWSConnection;
  aUser, aPassword: string; var Authenticated: Boolean);
begin
  Authenticated := (aUser = 'admin') and (aPassword = 's3cret');
end;
// uses: sgcWebSocket, sgcWebSocket_Server
TsgcWebSocketHTTPServer *WSServer = new TsgcWebSocketHTTPServer(this);
WSServer->Port = 80;

WSServer->OnConnect       = WSServerConnect;
WSServer->OnMessage       = WSServerMessage;
WSServer->OnDisconnect    = WSServerDisconnect;
WSServer->OnError         = WSServerError;
WSServer->OnAuthentication = WSServerAuthentication;

WSServer->Active = true;

void __fastcall TForm1::WSServerMessage(TsgcWSConnection *Connection,
    const UnicodeString Text)
{
  WSServer->WriteData(Text);
}
using esegece.sgcWebSockets;

var server = new TsgcWebSocketHTTPServer();
server.Port = 80;

server.OnConnect        += (conn) => Console.WriteLine("#connected: " + conn.IP);
server.OnMessage        += (conn, text) => server.WriteData(text);  // broadcast
server.OnDisconnect     += (conn, code) => Console.WriteLine("#disconnected: " + code);
server.OnAuthentication += (conn, user, pass, ref ok) => { ok = (user == "admin" && pass == "s3cret"); };

server.Active = true;

Co jest w środku

Opublikowane właściwości: 27, metody: 7, zdarzenia: 22, pobrane z dokumentacji komponentu.

Połączenie

Opublikowane właściwości: Active, Port, Bindings.

Wiadomości

Metody: Broadcast, WriteData, Ping.

Niezawodność

Opublikowane właściwości: HeartBeat, WatchDog, LoadBalancer.

Bezpieczeństwo

Opublikowane właściwości: Authentication, SSL, SSLOptions.

Cykl życia

Zdarzenia: OnStartup, OnShutdown, OnTCPConnect.

Dane

Zdarzenia: OnMessage, OnBinary, OnFragmented.

Specyfikacje i źródła

Autorytatywne źródła protokołów implementowanych przez ten komponent.

Dokumentacja i dema

Bezpośredni link do dokumentacji komponentu, gotowy do uruchomienia projekt demo i pobieranie wersji próbnej.

Pomoc online — TsgcWebSocketServer Pełna dokumentacja właściwości, metod i zdarzeń tego komponentu.
Projekt demonstracyjny — 01.WebSocket\02.Server Gotowy do uruchomienia projekt przykładowy. Dostarczany w pakiecie sgcWebSockets — pobierz wersję próbną poniżej.
Dokument techniczny (PDF) Funkcje, szybki start, przykłady kodu dla Delphi, C++ Builder i .NET oraz źródła pierwotne, wyłącznie dla tego komponentu.
Podręcznik użytkownika (PDF) Kompleksowy podręcznik obejmujący każdy komponent biblioteki.
Najkorzystniejsza oferta: All-AccessWszystkie produkty eSeGeCe, ze wsparciem Premium w cenie, już od €1,059 rocznie.
Zobacz cennik All-Access

Gotowy, by zbudować swój serwer?

Pobierz bezpłatną wersję próbną i utwórz a high-performance WebSocket server in minutes.