- This topic has 5 replies, 2 voices, and was last updated 11 years, 5 months ago by Anonymous.
-
AuthorPosts
-
July 22, 2013 at 23:21 #979AnonymousInactive
Hello, Im really new to this library, Im trying to setup my encryption over my client and server to all my packets but I cant get it to work since I have no connection over the client.
code:NetworkComms.ConnectionDefaultSendOptions.DataProcessors.Add(DPSManager.GetDataProcessor<DPSBase.RijndaelPSKEncrypter>()); DPSBase.RijndaelPSKEncrypter.AddPasswordToOptions(NetworkComms.ConnectionDefaultSendReceiveOptions.Options, "Your strong PSK"); NetworkComms.SendObject(type, serverIp, serverPort, data); NetworkComms.Shutdown();
Thats the client part, obviously is not working since but dont know how to solve it!
Over the server part I have this:
static void Main(string[] args) { String encryptionKey = "ljlhjf8uyfln23490jf;m21-=scm20--iflmk;"; DPSBase.RijndaelPSKEncrypter.AddPasswordToOptions(NetworkComms.DefaultSendReceiveOptions.Options, encryptionKey); //Trigger the method PrintIncomingMessage when a packet of type 'Message' is received //We expect the incoming object to be a string which we state explicitly by using <string> NetworkComms.AppendGlobalIncomingPacketHandler<string>("Message", PrintIncomingMessage); NetworkComms.AppendGlobalIncomingPacketHandler<string>("New", PrintIncomingUser); //Start listening for incoming connections TCPConnection.StartListening(true); //Let the user close the server Console.WriteLine("\nPress any key to close server."); Console.ReadKey(true); //We have used NetworkComms so we should ensure that we correctly call shutdown NetworkComms.Shutdown(); } /// <summary> /// Writes the provided message to the console window /// </summary> /// <param name="header">The packetheader associated with the incoming message</param> /// <param name="connection">The connection used by the incoming message</param> /// <param name="message">The message to be printed to the console</param> private static void PrintIncomingMessage(PacketHeader header, Connection connection, string message) { Console.WriteLine("Packet comming from " + connection.ToString() + " data sent '" + message + "'."); } private static void PrintIncomingUser(PacketHeader header, Connection connection, string message) { Console.WriteLine("New user " + connection.ToString() + " user type : '" + message + "'."); }
That seems to be working
Also another question is… I have checked the chat tutorial but I cant get how-to make my server reply to the packets the client send without using a new object.
ThanksJuly 23, 2013 at 10:08 #980AnonymousInactiveCalling
NetworkComms.Shutdown();
on the client prevents the server from replying.To reply directly from the server add the following code within
PrintIncomingMessage
andPrintIncomingUser
:connection.SendObject("packetTypeStr", replyData);
Regards,
MarcJuly 23, 2013 at 10:51 #981AnonymousInactiveAnd how should the client get the data ?
July 23, 2013 at 11:49 #982AnonymousInactiveYou need to configure packet handlers for the client as well using
NetworkComms.AppendGlobalIncomingPacketHandler(..
July 23, 2013 at 14:27 #987AnonymousInactiveAny quick example? thank you for your time and sorry.
July 23, 2013 at 16:17 #988AnonymousInactivePlease see the examples included in the ‘source bundle’ download or our tutorials section.
-
AuthorPosts
- You must be logged in to reply to this topic.