Start() public method

public Start ( ) : void
return void
Example #1
0
        public static unsafe void Main(string[] args)
        {
            var sendPool = new RioFixedBufferPool(10, 256);
            var recivePool = new RioFixedBufferPool(10, 256);
            var pool = new RioConnectionlessSocketPool(sendPool, recivePool, ADDRESS_FAMILIES.AF_INET, SOCKET_TYPE.SOCK_DGRAM, PROTOCOL.IPPROTO_UDP);
            RioConnectionlessSocket sock = null;

            var multicastAdress = IPAddress.Parse("238.0.3.15");

            try
            {
                sock = pool.Bind(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 3000));
            }
            catch (Exception)
            {
                sock = pool.Bind();
            }

            var nics = NetworkInterface.GetAllNetworkInterfaces()
                .Where(n => n.Supports(NetworkInterfaceComponent.IPv4))
                .Select(n => new { n.GetIPProperties().GetIPv4Properties().Index });

            sock.JoinMulticastGroup(multicastAdress, 0);

            RioSegmentReader r = new RioSegmentReader(sock);
            r.OnIncommingSegment = segment => Console.WriteLine(Encoding.ASCII.GetString(segment.DataPointer, segment.CurrentContentLength));
            r.Start();

            while (true)
            {
                sock.Send(Encoding.ASCII.GetBytes("Hello, i'm process " + Process.GetCurrentProcess().Id), new IPEndPoint(multicastAdress, 3000));
                Thread.Sleep(1000);
            }
        }
Example #2
0
        public static void ListenTcp()
        {
            RioTcpListener l = new RioTcpListener(new RioFixedBufferPool(16000, 65536), new RioFixedBufferPool(16000, 65536), (uint)Connections * 2, 16000, 16000);
            l.OnAccepted = s =>
            {
                RioStream r = new RioStream(s);
                int totalRecived = 0;
                int currentRecived = 0;
                var reader = new RioSegmentReader(s);

                var pb = new byte[PullBytes];
                if (Pattern == "PushPull")
                {
                    reader.OnIncommingSegment = seg =>
                    {
                        totalRecived += seg.CurrentContentLength;
                        currentRecived += seg.CurrentContentLength;
                        if (currentRecived >= PushBytes)
                        {
                            r.Write(pb, 0, pb.Length);
                            //s.WriteFixed(pb);
                            currentRecived = 0;
                        }
                    };
                    reader.Start();
                }
                else if (Pattern == "Pull")
                    r.Write(new byte[Transfer], 0, Transfer);
                //s.WriteFixed(new byte[Transfer]);
                else if (Pattern == "Push")
                {
                    reader.OnIncommingSegment = seg =>
                    {
                        totalRecived += seg.CurrentContentLength;
                    };
                    reader.Start();
                }
                else if (Pattern == "Duplex")
                {
                    s.Send(new byte[Transfer / 2]);
                    reader.OnIncommingSegment = seg =>
                    {
                        totalRecived += seg.CurrentContentLength;
                        //if (apa >= Transfer / 2)
                        //    tcs.SetResult(null);
                    };
                }
            };
            l.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), Port), 1024);
        }
Example #3
0
 static void ServeSegment(RioSocket socket)
 {
     socket.SetLinger(0);
     var reader = new RioSegmentReader<ServeState>(socket);
     reader.State = new ServeState();
     reader.State.leftoverLength = 0;
     reader.State.oldleftoverLength = 0;
     reader.State.reader = reader;
     reader.State.socket = socket;
     reader.OnIncommingSegment = ProcessSocket;
     reader.Start();
 }