Beispiel #1
0
        public RemoteProvider(string IP, int Port)
        {
            var socket = new NLCSocket(true, true);

            client = new NotLiteCode.Client(socket, true);

            client.Connect(IP, Port);
        }
        public RemoteProvider(IDBProvider db)
        {
            var socket = new NLCSocket(true, Helpers.GenerateSelfSignedCert("nalp", "localhost"));

            DB = db;

            server = new Server <SharedClass>(socket);
            server.OnServerClientConnected    += (x, y) => Helpers.Log($"NLC: Client {y.Client} connected!", ConsoleColor.Green);
            server.OnServerClientDisconnected += (x, y) => Helpers.Log($"NLC: Client {y.Client} disconnected!", ConsoleColor.Yellow);
            server.OnServerExceptionOccurred  += (x, y) => Helpers.Log($"NLC: Exception Occured! {y.Exception}", ConsoleColor.Red);
        }
Beispiel #3
0
        public Client(NLCSocket ClientSocket, bool UseCallbacks)
        {
            this.ClientSocket = ClientSocket;
            this.UseCallbacks = UseCallbacks;

            if (UseCallbacks && ClientSocket.BaseSocket.Connected)
            {
                if (!ClientSocket.ContinueSubscribing)
                {
                    ClientSocket.ContinueSubscribing = true;
                }

                ClientSocket.OnNetworkMessageReceived += OnCallbackMessageReceived;
            }
        }
Beispiel #4
0
        private static void Main(string[] args)
        {
            Console.Title = "NLC Server";

            var ServerSocket = new NLCSocket(new GroBufSerializationProvider(), UseSSL: true, ServerCertificate: GenerateSelfSignedCert("NLC", "localhost"));

            var Server = new Server <SharedClass>(ServerSocket);

            Server.OnServerClientConnected    += (x, y) => Log($"Client {y.Client} connected!", ConsoleColor.Green);
            Server.OnServerClientDisconnected += (x, y) => Log($"Client {y.Client} disconnected!", ConsoleColor.Yellow);
            Server.OnServerExceptionOccurred  += (x, y) => Log($"Exception Occured! {y.Exception}", ConsoleColor.Red);

            // This line intentionally left commented due to excessive lock contestion during performance testing (1000's of calls a second) which starves other performance critical threads thus skewing performance results
            //Server.OnServerMethodInvoked += (x, y) => Log($"Client {y.Client} {(y.WasErroneous ? "failed to invoke" : "invoked")} {y.Identifier} for {y.Duration.TotalMilliseconds}ms.", y.WasErroneous ? ConsoleColor.Yellow : ConsoleColor.Cyan);

            Server.Start();

            Log("Server Started!", ConsoleColor.Green);

            Process.GetCurrentProcess().WaitForExit();
        }
Beispiel #5
0
        private static async Task Main()
        {
            Console.Title = "NLC Client";

            // Create a socket with encryption enabled
            var ClientSocket = new NLCSocket(new GroBufSerializationProvider(), UseSSL: true, AllowInsecureCerts: true);

            Client = new Client(ClientSocket);

            Client.Connect("localhost", 1337);

            // Invoke our first remote method
            await Test();

            // Invoke a method that returns a string
            Console.WriteLine(await CombineTwoStringsAndReturn("I'm a ", "real boy!"));

            int l = 0;

            var t = Stopwatch.StartNew();

            // Execute a method as many times as we can in 1 second
            while (t.ElapsedMilliseconds < 1000)
            {
                await SpeedTest();

                l++;
            }

            t.Stop();

            Console.WriteLine("{0} calls in 1 second!", l);

            Client.Stop();
            Console.ReadLine();
        }
Beispiel #6
0
 public void ManuallyConnectSocket(NLCSocket Socket)
 {
     OnNetworkClientConnected(null, new OnNetworkClientConnectedEventArgs(Socket));
 }
Beispiel #7
0
 public Server(NLCSocket ServerSocket)
 {
     this.ServerSocket = ServerSocket;
     RegisterFunctions();
 }
Beispiel #8
0
 public RemoteClient(NLCSocket Socket)
 {
     this.Socket      = Socket;
     this.SharedClass = new T();
 }
Beispiel #9
0
 public void DetatchFromSocket(NLCSocket Socket)
 {
     Socket.OnNetworkClientDisconnected -= NetworkClientDisconnected;
     Socket.OnNetworkExceptionOccurred  -= NetworkExceptionOccurred;
     Socket.OnNetworkMessageReceived    -= OnNetworkMessageReceived;
 }
Beispiel #10
0
 public Client(NLCSocket ClientSocket) : this(ClientSocket, false)
 {
 }