Home Forums Support Encryption connection

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #979
    Anonymous
    Inactive

    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.
    Thanks

    #980
    Anonymous
    Inactive

    Calling NetworkComms.Shutdown(); on the client prevents the server from replying.

    To reply directly from the server add the following code within PrintIncomingMessage and PrintIncomingUser:

    connection.SendObject("packetTypeStr", replyData);

    Regards,
    Marc

    #981
    Anonymous
    Inactive

    And how should the client get the data ?

    #982
    Anonymous
    Inactive

    You need to configure packet handlers for the client as well using NetworkComms.AppendGlobalIncomingPacketHandler(..

    #987
    Anonymous
    Inactive

    Any quick example? thank you for your time and sorry.

    #988
    Anonymous
    Inactive

    Please see the examples included in the ‘source bundle’ download or our tutorials section.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.