Wysyłanie pliku przez WebSocket w .NET

· Komponenty

Od wersji sgcWebSockets 4.4.8 protokół WebSocket Protocol Files jest obsługiwany przez bibliotekę sgcWebSockets .NET.

Protokół ten umożliwia wysyłanie plików za pomocą binarnego transportu WebSocket. Obsługuje duże pliki przy niskim zużyciu pamięci.

Funkcje

Code Example 

Aby wysłać plik na serwer, wywołaj metodę SendFile protokołu Files i przekaż pełną FileName jako argument.

Plik odebrany przez serwer jest domyślnie zapisywany w tym samym katalogu co plik wykonywalny serwera lub w ścieżce ustawionej we właściwości Files.SaveDirectory. 

// ... Create Server
TsgcWebSocketServer oServer = new TsgcWebSocketServer();
TsgcWSPServer_Files oServer_Files = new TsgcWSPServer_Files();
oServer_Files.Server = oServer;
oServer.Host = "127.0.0.1";
oServer.Port = 8080;
// ... Create Client
TsgcWebSocketClient oClient = new TsgcWebSocketClient();
oClient.URL = "ws://127.0.0.1:8080";
// ... Create Protocol
TsgcWSPClient_Files oClient_Files = new TsgcWSPClient_Files();
oClient_Files.Client = oClient;
// ... Start Server
oServer.Active = true;
// ... Connect client and Send File
if oClient.Connect() then
  oClient_Files.SendFile("c:\Documents\yourfile.txt");