Servidor WebSocket Delphi
TsgcWebSocketHTTPServer — um componente de servidor WebSocket e HTTP multithread com suporte a IOCP/EPOLL, SSL/TLS, autenticação e servimento de arquivos estáticos.
TsgcWebSocketHTTPServer — um componente de servidor WebSocket e HTTP multithread com suporte a IOCP/EPOLL, SSL/TLS, autenticação e servimento de arquivos estáticos.
Servidor HTTP + WebSocket — processa handshakes wss://, faz broadcast de mensagens e já inclui TLS, autenticação, registro no load-balancer e HTTP/2.
TsgcWebSocketHTTPServer
WebSocket — RFC 6455
Windows, macOS, Linux, iOS, Android
Professional / Enterprise
Solte um TsgcWebSocketHTTPServer, defina Port e SSL, conecte o OnMessage e o servidor está pronto.
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;
27 propriedades publicadas, 7 métodos, 22 eventos — extraídos da referência do componente.
Propriedades publicadas: Active, Port, Bindings.
Métodos: Broadcast, WriteData, Ping.
Propriedades publicadas: HeartBeat, WatchDog, LoadBalancer.
Propriedades publicadas: Authentication, SSL, SSLOptions.
Eventos: OnStartup, OnShutdown, OnTCPConnect.
Eventos: OnMessage, OnBinary, OnFragmented.
Acesse a referência do componente, obtenha o projeto demo pronto para executar e baixe a versão de avaliação.
| Ajuda online — TsgcWebSocketServer Referência completa de propriedades, métodos e eventos deste componente. | Abrir | |
| Projeto de demonstração — 01.WebSocket\02.Server Projeto de exemplo pronto para executar. Acompanha o pacote sgcWebSockets — baixe a versão de avaliação abaixo. | Abrir | |
| Documento técnico (PDF) Recursos, início rápido, exemplos de código para Delphi, C++ Builder e .NET e referências de fontes primárias — somente este componente. | Abrir | |
| Manual do usuário (PDF) Manual abrangente cobrindo todos os componentes da biblioteca. | Abrir |