Ejemplo n.º 1
0
        public void StartListen()
        {
            var settings          = new RSocketSettings();
            var remoteEndPoint    = new IPEndPoint(IPAddress.Any, 7000);
            var cancellationToken = new CancellationTokenSource();

            Socket = new RServerSocket(settings, remoteEndPoint, new RByteSerialization(), null);

            Socket.ClientDiscoverMessage += OnNewClient;
            Socket.ClientDisconnected    += OnCloseClient;
            Socket.StartListen();
            Console.WriteLine("Server started.");

            // Register receiver
            Socket.OnReceiveData = async(byte[] data, EndPoint ep) =>
            {
                Console.WriteLine($"Received from: {ep}, message: " + ASCIIEncoding.UTF8.GetString(data));

                await Task.Delay(100);

                string message     = "hello-client";
                var    messagedata = Encoding.ASCII.GetBytes("hello-client!");
                Socket.Send(ref messagedata, ep, RQoSType.Realiable);

                Console.WriteLine($"Sent message: {message}, to: {ep}");

                this.Socket.DisconnectEndPoint(ep);
            };
        }
Ejemplo n.º 2
0
        public void Connect()
        {
            var settings          = new RSocketSettings();
            var remoteEndPoint    = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7000);
            var cancellationToken = new CancellationTokenSource();

            Socket = new RClientSocket(settings, new RByteSerialization(), null);

            Socket.Connected += OnConnectSuccessful;
            Socket.Error     += OnConnectFailed;
            Socket.Connect(remoteEndPoint);
            Socket.Disconnected += OnDisconnect;
            Console.WriteLine("Client started.");
        }