blob: 593dadfe2cde829259e6fac2270f09b3c0806668 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
using System;
using CommonLib;
using Hik.Communication.Scs.Communication.EndPoints.Tcp;
using Hik.Communication.Scs.Communication.Messages;
using Hik.Communication.Scs.Server;
/* This application is build to demonstrate a CUSTOM WIRE PROTOCOL usage with SCS framework.
* This server application listens incoming messages from client applications using MyWireProtocol class.
*/
namespace ServerApp
{
public class Program
{
static void Main()
{
var server = ScsServerFactory.CreateServer(new ScsTcpEndPoint(10033));
server.WireProtocolFactory = new MyWireProtocolFactory(); //Set custom wire protocol factory!
server.ClientConnected += server_ClientConnected;
server.Start();
Console.WriteLine("Press enter to stop server");
Console.ReadLine();
server.Stop();
}
static void server_ClientConnected(object sender, ServerClientEventArgs e)
{
Console.WriteLine("A new client is connected. Address: " + e.Client.RemoteEndPoint);
e.Client.MessageReceived += Client_MessageReceived;
}
static void Client_MessageReceived(object sender, MessageEventArgs e)
{
Console.WriteLine("A client sent a message: " + ((ScsTextMessage) e.Message).Text);
}
}
}
|