summaryrefslogtreecommitdiffstats
path: root/samples/SimpleMessaging/SynchronizedClient/Program.cs
diff options
context:
space:
mode:
authorHalil İbrahim Kalkan <hi_kalkan@yahoo.com>2013-04-08 21:44:58 +0300
committerHalil İbrahim Kalkan <hi_kalkan@yahoo.com>2013-04-08 21:44:58 +0300
commit79953cb56cda204f190ffcd9995b27ebea25e62d (patch)
treede939755c2e32eaa5fa3e41e21114e1c727ed0a4 /samples/SimpleMessaging/SynchronizedClient/Program.cs
parent934c543eb6b0bd7173038e45a7dac0241d091da4 (diff)
downloadscs-79953cb56cda204f190ffcd9995b27ebea25e62d.zip
scs-79953cb56cda204f190ffcd9995b27ebea25e62d.tar.gz
scs-79953cb56cda204f190ffcd9995b27ebea25e62d.tar.bz2
Adding to github
Adding to github
Diffstat (limited to 'samples/SimpleMessaging/SynchronizedClient/Program.cs')
-rw-r--r--samples/SimpleMessaging/SynchronizedClient/Program.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/samples/SimpleMessaging/SynchronizedClient/Program.cs b/samples/SimpleMessaging/SynchronizedClient/Program.cs
new file mode 100644
index 0000000..aa7e3d2
--- /dev/null
+++ b/samples/SimpleMessaging/SynchronizedClient/Program.cs
@@ -0,0 +1,46 @@
+using System;
+using Hik.Communication.Scs.Client;
+using Hik.Communication.Scs.Communication.EndPoints.Tcp;
+using Hik.Communication.Scs.Communication.Messages;
+using Hik.Communication.Scs.Communication.Messengers;
+
+/* This program is build to demonstrate a client application that connects to a server
+ * and sends/receives messages in using SynchronizedMessenger.
+ */
+
+namespace SynchronizedClient
+{
+ class Program
+ {
+ static void Main()
+ {
+ Console.WriteLine("Press enter to connect to the server...");
+ Console.ReadLine(); //Wait user to press enter
+
+ //Create a client object to connect a server on 127.0.0.1 (local) IP and listens 10085 TCP port
+ using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10085)))
+ {
+ //Create a SynchronizedMessenger that uses the client as internal messenger.
+ using (var synchronizedMessenger = new SynchronizedMessenger<IScsClient>(client))
+ {
+ synchronizedMessenger.Start(); //Start synchronized messenger messenger
+ client.Connect(); //Connect to the server
+
+ Console.Write("Write some message to be sent to server: ");
+ var messageText = Console.ReadLine(); //Get a message from user
+
+ //Send a message to the server
+ synchronizedMessenger.SendMessage(new ScsTextMessage(messageText));
+
+ //Receive a message from the server
+ var receivedMessage = synchronizedMessenger.ReceiveMessage<ScsTextMessage>();
+
+ Console.WriteLine("Response to message: " + (receivedMessage.Text));
+
+ Console.WriteLine("Press enter to disconnect from server...");
+ Console.ReadLine(); //Wait user to press enter
+ }
+ }
+ }
+ }
+}