This demo shows how build a websocket client, using TsgcWebSocketClient.
client.Host = txtHost.Text;
client.Port = Int32.Parse(txtPort.Text);
client.Options.Parameters = txtParameters.Text;
client.TLS = chkTLS.Checked;
client.TLSOptions.Version = TwsTLSVersions.tls1_2;
client.TLSOptions.IOHandler = TwsTLSIOHandler.iohSChannel;
client.Specifications.RFC6455 = chkOverWebSocket.Checked;
client.Proxy.Enabled = chkProxy.Checked;
client.Proxy.Username = txtProxyUsername.Text;
client.Proxy.Password = txtProxyPassword.Text;
client.Proxy.Host = txtProxyHost.Text;
if (txtProxyPort.Text != "")
{
client.Proxy.Port = Int32.Parse(txtProxyPort.Text);
}
client.Extensions.PerMessage_Deflate.Enabled = chkCompressed.Checked;
client.Active = true;
Use the following events to control the client flow: when connects, disconnects, receives a message, an error is detected...
private void OnExceptionEvent(TsgcWSConnection Connection, Exception E)
{
DoLog("#exception: " + E.Message);
}
private void OnConnectEvent(TsgcWSConnection Connection)
{
DoLog("#connected: " + Connection.IP);
}
private void OnMessageEvent(TsgcWSConnection Connection, string Text)
{
DoLog(Text);
}
private void OnDisconnectEvent(TsgcWSConnection Connection, int CloseCode)
{
DoLog("Disconnected (" + CloseCode.ToString() + "): " + Connection.IP);
}
private void OnErrorEvent(TsgcWSConnection Connection, string Error)
{
DoLog("#error: " + Connection.IP + " - " + Error);
}