1. Create a new Window Forms Application
2. Drop a TsgcWebSocketServer onto a Form.
3. On Events Tab, Double click OnMessage Event, and type following code:
private void OnMessage(TsgcWSConnection Connection, const string Text) { MessageBox.Show("Message Received From Client: " + Text); }
4. Drop a Button onto the Form, Double Click and type this code:
TsgcWebSocketServer1.Active = True;
Server can be configured to use SSL Certificates, in order to get a Production Server with a server certificate, you must purchase a Certificate from a well known provider: Namecheap, godaddy, Thawte... For testing purposes you can use a self-signed certificate (check out in Demos/Chat which uses a self-signed certificate).
Certificate must be in PEM format, PEM (from Privacy Enhanced Mail) is defined in RFCs 1421 through 1424, this is a container format that may include just the public certificate (such as with Apache installs, and CA certificate files /etc/ssl/certs), or may include an entire certificate chain including public key, private key, and root certificates. To create a single pem certificate, just open your private key file, copy the contents and paste on certificate file.
Simple SSL Configuration
Example: configure SSL in IP 127.0.0.1 and Port 443
oServer = new TsgcWebSocketServer(); oServer.SSL = true; oServer.SSLOptions.CertFile = "c:\certificates\mycert.pem"; oServer.SSLOptions.KeyFile = "c:\certificates\mycert.pem"; oServer.SSLOptions.RootCertFile = "c:\certificates\mycert.pem"; oServer.SSLOptions.Port = 443; oServer.Port = 443; oServer.Active = true;
Once server is started and OnShutdown event is fired, sometimes server can stopped for any reason. If you want to restart server after an unexpected close, you can use WatchDog property.
If WatchDog is enabled, when server detects a Shutdown, WatchDog try to restart again every X seconds until server is active again.
Example: restart every 10 seconds after an unexpected stop with unlimited attempts.
oServer = new TsgcWebSocketServer(); oServer.WatchDog.Interval = 10; oServer.WatchDog.Attempts = 0; oServer.WatchDog.Enabled = true; oServer.Active = true;
Once your client has connected to server, sometimes connection can be closed due to poor signal, connection errors... use Heartbeat to keep connection alive.
HeartBeat property allows to send a Ping every X seconds to maintain connection alive. Some servers, close TCP connections if there is no data exchanged between peers. HeartBeat solves this problem, sending a ping every a specific interval. Usually this is enough to maintain a connection active, but you can set a TimeOut interval if you want to close connection if a response from client is not received after X seconds.
Example: send a ping to all connected clients every 30 seconds
oServer = new TsgcWebSocketServer(); oServer.HeartBeat.Interval = 30; oServer.HeartBeat.Timeout = 0; oServer.HeartBeat.Enabled = true; oServer.Active = true;
TsgcWebSocket server supports 3 types of Authentications:
Once client has connected to server, server can send text messages. To send a Text Message, just call WriteData() method to send a message to a single client or use Broadcast to send a message to all clients.
Call To WriteData() method and send a Text message.
TsgcWebSocketClient1.WriteData("guid", "My First sgcWebSockets Message!.");
When server receives a Text Message, OnMessage event is fired, just read Text parameter to know the string of message received.
void OnMessage(TsgcWSConnection Connection, string Text) { MessageBox.Show("Message Received from Client: " + Text); }
By default, server uses neAsynchronous method to dispatch OnMessage event, this means that this event is executed on the context of Main Thread, so it's thread-safe to update any control of a form for example.
If your server receives lots of messages or you need to control the synchronization with other threads, set NotifyEvents property to neNoSync, this means that OnMessage event will be executed on the context of connection thread, so if you require to update any control of a form or access shared objects, you must implement your own synchronization methods.
.NET Components. Share your code using our sgcWebSockets library for your .NET projects. Includes Server, Clients and several protocols for building and connecting to applications.
.NET
Real Time Monitor
Shows 3 gauges which are updated automatically every x seconds.
SGC Protocol (RPC, PubSub, Transactional Messages, Acknowledgement, QoS...)
Shows the use of subscriptions to a custom channel, transactions, Remote Procedure Calls, Acknowledgements...
Presence Protocol (PubSub, Publish Messages, Members subscribed...)
Allows to know who is subscribed to a channel, example: chat rooms, collaborators on a document, people viewing the same web page, competitors in a game...
DevExtreme Data Grid
This example shows how to use the DevExtreme Data Grid with a sgcWebSockets server and the Dataset protocol updating the stock quotes in real-time.
KendoUI Grid
Use KendoUI grid to create/edit/delete records and all changes will be broadcasted to all clients connected.
Real Time Quotes
Shows a grid where quotes are automatically updated in Real Time.
AppRTC (Audio And Video) using WebSockets
Broadcast audio and video between 2 clients using AppRTC code.
Multi-user Video Conference
Multi-user (many-to-many) video chat using mesh networking model.
Screen Sharing
Multi-user (one-to-many) screen sharing using star topology.
Video BroadCasting
Multi-user (one-to-many) video broadcasting using star topology.
Real Time Tickets
Create customer clients and all changes are broadcasted to all clients connected.
Chat
Simple chat to send/receive messages from others.
Binary Messages
Broadcast images to all clients connected.
WAMP Protocol (RPC and PubSub)
Show the use of WAMP protocol.
WebRTC (Audio and Video) via WebSockets
Broadcast audio and video between 2 clients.
Server-Sent Events
Shows the use of Server-Sent events.
sgcWebSockets Community for Windows, Linux64 and OSX64
sgcWebSockets .NET Community
sgcWebSockets .NET Community Nuget Package
Includes a set of compiled demos which shows the use of sgcWebSockets
Download
ASP.NET Core React Demo
Download
Buy now your License to get sgcWebSockets source code: .NET package includes full source code for assemblies in the PROFESSIONAL edition, but if you require to rebuild sgcWebSockets.dll, select the ENTERPRISE edition.
When you buy a license, you'll get access to source code and 1 Year of updates.
If you have any doubts or questions, please Contact us for details.
Which support is included?
After you register your license, you get 1 year of updates and support by our online HelpDesk, public forums or by email.
How much time I need to wait between I purchase and I get the product?
Once registered, you get a link to download your package, so you don't need to wait, you'll get the package automatically after you purchase.
Where can I download updates of the library?
After successful registration, you get an user and password to login our website and you can download latest source version. When we release a new version, you'll get notified by mail.
Is there a Trial version of the sgcWebsockets?
Yes, you can download a trial version with precompiled units. This Trial is fully functional by limited in time.
Is Source Code available?
Yes, full source code is included only in sgcWebSockets .NET Enterprise edition.
How is your license scheme?
Is per-developer, so each developer that uses our product must have their own license.
Does the license expire?
No, the licenses are perpetual (with 12 months of free updates) and are royalty-free. Perpetual means that after expiration, you can use our components without limits, but this doesn't mean that you will get updates forever.
There are discounts if I renew a license?
Yes, if your subscription includes renewal discounts, a mail is sent automatically, when your license expires, with a discount code.
More info about checkout?
Yes, you can check following page with more info about checkout process.