static void Main() { var serverPublicKey = new X509Certificate2(@"C:\Users\node\Desktop\scs\SSLSamples\CertificateFiles\Server\publicKey.cer"); 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))) using (var client = SslScsClientFactory.CreateSslClient(new ScsTcpEndPoint("127.0.0.1", 10085) , serverPublicKey , "127.0.0.1")) { //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 } } }
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 } } }
public static void Run() { Console.WriteLine("Press enter to connect to server and send " + Consts.MessageCount + " messages."); Console.ReadLine(); //using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10033))) using (var client = SslScsClientFactory.CreateSslClient(new ScsTcpEndPoint("127.0.0.1", 10033), Consts.ServerPublicKey, "127.0.0.1")) { client.WireProtocol = new MyWireProtocol(); using (var synchronizedMessenger = new SynchronizedMessenger <IScsClient>(client)) { synchronizedMessenger.Start(); client.Connect(); for (var i = 0; i < Consts.MessageCount; i++) { synchronizedMessenger.SendMessage(new ScsTextMessage("Hello from client!")); var reply = synchronizedMessenger.ReceiveMessage <ScsTextMessage>(); } } Console.WriteLine("Press enter to disconnect from server"); Console.ReadLine(); } }
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 } } }
public static void Run() { //Console.WriteLine("Press enter to connect to server and send " + Consts.MessageCount + " messages."); //Console.ReadLine(); using (var client = ScsClientFactory.CreateClient(Consts.ServerEndpoint)) { client.WireProtocol = new MyWireProtocol(); client.MessageReceived += client_MessageReceived; using (var synchronizedMessenger = new SynchronizedMessenger<IScsClient>(client)) { synchronizedMessenger.Start(); try { Console.WriteLine("Connecting to " + Consts.ServerEndpoint); client.Connect(); Console.WriteLine("Sending " + Consts.MessageCount + " messages."); for (var i = 0; i < Consts.MessageCount; i++) { Consts.PrintProgress(i); synchronizedMessenger.SendMessage(new ScsTextMessage("Hello from client!")); var reply = synchronizedMessenger.ReceiveMessage<ScsTextMessage>(); } } catch (Exception exception) { Console.WriteLine(exception.Message); } } Console.WriteLine("Press enter to close application."); Console.ReadLine(); } }
public static void Run() { Console.WriteLine("Press enter to connect to server and send " + Consts.MessageCount + " messages."); Console.ReadLine(); using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint("127.0.0.1", 10033))) { using (var synchronizedMessenger = new SynchronizedMessenger<IScsClient>(client)) { synchronizedMessenger.Start(); client.Connect(); for (var i = 0; i < Consts.MessageCount; i++) { synchronizedMessenger.SendMessage(new ScsTextMessage("Hello from client!")); var reply = synchronizedMessenger.ReceiveMessage<ScsTextMessage>(); } } Console.WriteLine("Press enter to disconnect from server"); Console.ReadLine(); } }
public static bool CheckConnectionMessage(string connectString) { try { using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(MainWindow.launcherConfig.ServerIP, Convert.ToInt32(MainWindow.launcherConfig.ServerPort)))) { client.WireProtocol = new KeyProtocol(); using (var synchronizedMessenger = new SynchronizedMessenger <IScsClient>(client)) { //setup response manager synchronizedMessenger.Start(); client.Connect(); synchronizedMessenger.SendMessage(new ScsTextMessage(connectString)); var replyPacket = synchronizedMessenger.ReceiveMessage <ScsTextMessage>(); if (replyPacket == null) { client.Disconnect(); return(false); } // string data = replyPacket.Text; switch (data) { //LoginPacket Response case "4099": //Auth FAILED PASS PrintMessage("Sorry! Authorization for this Account failed, is your Password correct?"); client.Disconnect(); return(false); case "4098": //Auth OK PrintMessage("Yes! Authorization for this Account was successfull!"); client.Disconnect(); return(true); case "4100": //Account Unbanned PrintMessage("Yes! Your Account got Unbanned, have fun to play!"); client.Disconnect(); return(true); case "4101": //Account Banned PrintMessage("Sorry! but your Account is Banned, please contact the support for more information!"); client.Disconnect(); return(false); case "4102": //Account Online PrintMessage("Wtf! You are already Online, if its not you please contact the Support!"); client.Disconnect(); return(false); //Register Packet Response case "8194": //Account already Exists PrintMessage("Sorry! Account Registration failed, Account already exists!"); client.Disconnect(); return(false); case "8195": //Account creation successfull PrintMessage("Yes! Registration for this Account was successful!"); client.Disconnect(); return(true); default: PrintMessage("PacketFailure %$§&*$" + replyPacket.Text); client.Disconnect(); return(false); } } } } catch (Exception ex) { MessageBox.Show("Connecting error!\n" + ex, "Error"); return(false); } }
public static bool CheckConnectionMessage(string connectString) { try { using (var client = ScsClientFactory.CreateClient(new ScsTcpEndPoint(MainWindow.launcherConfig.ServerIP, Convert.ToInt32(MainWindow.launcherConfig.ServerPort)))) { client.WireProtocol = new KeyProtocol(); using (var synchronizedMessenger = new SynchronizedMessenger<IScsClient>(client)) { //setup response manager synchronizedMessenger.Start(); client.Connect(); synchronizedMessenger.SendMessage(new ScsTextMessage(connectString)); var replyPacket = synchronizedMessenger.ReceiveMessage<ScsTextMessage>(); if (replyPacket == null) { client.Disconnect(); return false; } // string data = replyPacket.Text; switch (data) { //LoginPacket Response case "4099"://Auth FAILED PASS PrintMessage("Sorry! Authorization for this Account failed, is your Password correct?"); client.Disconnect(); return false; case "4098"://Auth OK PrintMessage("Yes! Authorization for this Account was successfull!"); client.Disconnect(); return true; case "4100"://Account Unbanned PrintMessage("Yes! Your Account got Unbanned, have fun to play!"); client.Disconnect(); return true; case "4101"://Account Banned PrintMessage("Sorry! but your Account is Banned, please contact the support for more information!"); client.Disconnect(); return false; case "4102"://Account Online PrintMessage("Wtf! You are already Online, if its not you please contact the Support!"); client.Disconnect(); return false; //Register Packet Response case "8194"://Account already Exists PrintMessage("Sorry! Account Registration failed, Account already exists!"); client.Disconnect(); return false; case "8195"://Account creation successfull PrintMessage("Yes! Registration for this Account was successful!"); client.Disconnect(); return true; default: PrintMessage("PacketFailure %$§&*$" + replyPacket.Text); client.Disconnect(); return false; } } } } catch (Exception )//ex) { //MessageBox.Show("Connecting error!\n" + ex,"Error"); return false; } }