/// <summary>
 /// Initializes a new instance of the <see cref="ServerClientContext" /> class.
 /// </summary>
 /// <param name="readBuffer">The read buffer.</param>
 public ServerClientContext(IBufferSlice readBuffer)
 {
     if (readBuffer == null) throw new ArgumentNullException("readBuffer");
     _readBuffer = readBuffer;
     _readStream = new SliceStream(ReadBuffer);
     _readArgs = new SocketAsyncEventArgs();
     _readArgs.Completed += OnReadCompleted;
     _readArgs.SetBuffer(_readBuffer.Buffer, _readBuffer.Offset, _readBuffer.Count);
     _writer = new SocketWriter();
     _writer.Disconnected += OnWriterDisconnect;
 }
        public void SendOneMessage()
        {
            var connection = SocketTestTools.CreateConnection();
            var writer = new SocketWriter();
            writer.Assign(connection.Client);

            var msg = Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\nServer: localhost\r\nContent-Length: 0\r\n\r\n");
            writer.Send(new SliceSocketWriterJob(new BufferSlice(msg, 0, msg.Length), msg.Length));

            var buffer = new byte[65535];
            Assert.Equal(msg.Length, connection.Server.Receive(buffer));
        }
Пример #3
0
        internal bool RegisterWithDA( )
        {
            SocketWriter.WriteToSocket(NWStream, "FileServer");
            SocketWriter.WriteToSocket(NWStream, "REG" + " " + Program.ipAddress + " " + Program.portNumber);
            String Response = SocketReader.ReadFromSocket(NWStream, tcpClient.ReceiveBufferSize);

            if (Response == "OK")
            {
                return(true);
            }

            return(false);
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerClientContext" /> class.
 /// </summary>
 /// <param name="readBuffer">The read buffer.</param>
 public ServerClientContext(IBufferSlice readBuffer)
 {
     if (readBuffer == null)
     {
         throw new ArgumentNullException("readBuffer");
     }
     this.readBuffer          = readBuffer;
     this.readStream          = new SliceStream(this.ReadBuffer);
     this.readArgs            = new SocketAsyncEventArgs();
     this.readArgs.Completed += this.OnReadCompleted;
     this.readArgs.SetBuffer(this.readBuffer.Buffer, this.readBuffer.Offset, this.readBuffer.Count);
     this.writer = new SocketWriter();
     this.writer.Disconnected += this.OnWriterDisconnect;
 }
Пример #5
0
        public void SendOneMessage()
        {
            var connection = SocketTestTools.CreateConnection();
            var writer     = new SocketWriter();

            writer.Assign(connection.Client);

            var msg = Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\nServer: localhost\r\nContent-Length: 0\r\n\r\n");

            writer.Send(new SliceSocketWriterJob(new BufferSlice(msg, 0, msg.Length), msg.Length));

            var buffer = new byte[65535];

            Assert.Equal(msg.Length, connection.Server.Receive(buffer));
        }
        public void DisconnectSend()
        {
            var connection = SocketTestTools.CreateConnection();
            var writer = new SocketWriter();
            writer.Assign(connection.Client);

            connection.Server.Shutdown(SocketShutdown.Send);
            connection.Server.Disconnect(false);

            var buffer2 = new byte[10];
            var bytes = connection.Client.Receive(buffer2);
            connection.Client.Shutdown(SocketShutdown.Send);
            connection.Client.Close();

            var msg = Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\nServer: localhost\r\nContent-Length: 0\r\n\r\n");
            Assert.Throws<InvalidOperationException>(
                () => writer.Send(new SliceSocketWriterJob(new BufferSlice(msg, 0, msg.Length), msg.Length)));
        }
Пример #7
0
        public static (double, double, TimeSpan) RunSmall()
        {
            var      tempFileName             = "abc1.sock";
            var      serverCancellationSource = new CancellationTokenSource();
            var      clientCancellationSource = new CancellationTokenSource();
            var      stopWatch = Stopwatch.StartNew();
            TimeSpan elapesedTime;
            ulong    writer_count = 0, reader_count = 0;

            try
            {
                var sw    = new SocketWriter();
                var sr    = new SocketReader();
                var socks = UnixSocketRunner.GetUnixSockets(ProtocolType.Unspecified, tempFileName);

                var wirter = sw.Run(DataType.Small, serverCancellationSource.Token, socks.Server);

                var reader = sr.Run(DataType.Small, clientCancellationSource.Token, socks.Client);

                serverCancellationSource.CancelAfter(TimeSpan.FromSeconds(10));

                writer_count = wirter.Result;

                clientCancellationSource.Cancel();

                reader_count = reader.Result;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
            finally
            {
                elapesedTime = stopWatch.Elapsed;
                stopWatch.Stop();

                File.Delete(tempFileName);
            }
            double readen_kbPerS = (reader_count / 1024) / elapesedTime.TotalSeconds;
            double writen_kbPerS = (writer_count / 1024) / elapesedTime.TotalSeconds;

            return(readen_kbPerS, writen_kbPerS, elapesedTime);
        }
Пример #8
0
        public void DisconnectSend()
        {
            var connection = SocketTestTools.CreateConnection();
            var writer     = new SocketWriter();

            writer.Assign(connection.Client);

            connection.Server.Shutdown(SocketShutdown.Send);
            connection.Server.Disconnect(false);

            var buffer2 = new byte[10];
            var bytes   = connection.Client.Receive(buffer2);

            connection.Client.Shutdown(SocketShutdown.Send);
            connection.Client.Close();

            var msg = Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\nServer: localhost\r\nContent-Length: 0\r\n\r\n");

            Assert.Throws <InvalidOperationException>(
                () => writer.Send(new SliceSocketWriterJob(new BufferSlice(msg, 0, msg.Length), msg.Length)));
        }
Пример #9
0
        public static (double, double, TimeSpan) RunBig()
        {
            var      serverCancellationSource = new CancellationTokenSource();
            var      clientCancellationSource = new CancellationTokenSource();
            var      stopWatch = Stopwatch.StartNew();
            TimeSpan elapesedTime;
            ulong    writer_count = 0, reader_count = 0;

            try
            {
                var sw    = new SocketWriter();
                var sr    = new SocketReader();
                var socks = TcpSocketRunner.GetSockets();

                var wirter = sw.Run(DataType.Big, serverCancellationSource.Token, socks.Server);

                var reader = sr.Run(DataType.Big, clientCancellationSource.Token, socks.Client);

                serverCancellationSource.CancelAfter(TimeSpan.FromSeconds(10));

                writer_count = wirter.Result;

                clientCancellationSource.Cancel();

                reader_count = reader.Result;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                elapesedTime = stopWatch.Elapsed;
                stopWatch.Stop();
            }
            double readen_kbPerS = (reader_count / 1024) / elapesedTime.TotalSeconds;
            double writen_kbPerS = (writer_count / 1024) / elapesedTime.TotalSeconds;

            return(readen_kbPerS, writen_kbPerS, elapesedTime);
        }
Пример #10
0
        public (double BytesReaden, TimeSpan RunTime, TimeSpan SerialzationTime) RunBig()
        {
            var      serverCancellationSource = new CancellationTokenSource();
            var      clientCancellationSource = new CancellationTokenSource();
            var      stopWatch = Stopwatch.StartNew();
            TimeSpan elapesedTime;
            ulong    reader_count = 0;

            try
            {
                var sw    = new SocketWriter();
                var socks = LocalSocketUnserializer.GetLocalSockets();

                var wirter = sw.Run(DataType.Big, serverCancellationSource.Token, socks.Server);

                var readerTask = this.reader.Run(DataType.Big, clientCancellationSource.Token, socks.Client);

                serverCancellationSource.CancelAfter(TimeSpan.FromSeconds(10));

                _ = wirter.Result;

                clientCancellationSource.Cancel();

                reader_count = readerTask.Result;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                elapesedTime = stopWatch.Elapsed;
                stopWatch.Stop();
                this.serializationTime = this.reader.StopWatch.Elapsed;
            }
            double readen_kbPerS = (reader_count / 1024) / elapesedTime.TotalSeconds;

            return(readen_kbPerS, this.serializationTime, elapesedTime);
        }
Пример #11
0
        public void CanWrite()
        {
            using (var ms = new MemoryStream())
                using (var writer = new SocketWriter(ms, 8))
                    using (var reader = new StreamReader(ms))
                    {
                        writer.Write("777\r\n");
                        writer.Write("888\r\n");
                        writer.Write("999\r\n");
                        writer.Write("x");
                        writer.Write("#");
                        writer.Write("\r\n");

                        writer.Flush();
                        ms.Seek(0, SeekOrigin.Begin);

                        Assert.AreEqual("777", reader.ReadLine());
                        Assert.AreEqual("888", reader.ReadLine());
                        Assert.AreEqual("999", reader.ReadLine());
                        Assert.AreEqual("x#", reader.ReadLine());
                    }
        }
Пример #12
0
        public void CanReadUTF8Lines()
        {
            var str1 = "프로디지(The Prodigy)는 리엄 하울렛(Liam Howlett)이 주축이 되어 1990년 영국 에식스(Essex)에서 결성된 일렉트로닉 음악 그룹이다. 케미컬 브라더스(Chemical Brothers), 팻보이 슬림(Fatboy Slim), 크리스털 메소드(The Crystal Method) 등과 함께 빅비트(big beat) 일렉트로닉 댄스 음악의 선두주자로 꼽힌다. 현재까지 세계적으로 1600백만장 이상의 앨범 판매고를 올렸으며, 이는 일렉트로닉 음악 역사상 최고 음반 판매고이다.[1] 프로디지의 음악은 1990년대 초반의 레이브(rave), 하드코어 테크노(hardcore techno), 인더스트리얼(industrial)부터 이후의 얼터너티브 록(alternative rock)과 펑크(punk) 보컬을 가미한 빅비트까지 다양한 스타일이다.";
            var str2 = "현재, 멤버는 리엄 하울렛(Liam Howlett: 작곡/키보드), 키쓰 플린트(Keith Flint: 댄서/보컬), 막심(Maxim: MC/보컬)이다. 여성 댄서이자 보컬을 맡았던 샤키(Sharky)는 밴드 결성 초반에, 댄서이자 간혹 라이브에서 키보드를 맡았던 리로이 쏜힐(Leeroy Thornhill)은 2000년에 밴드에서 탈퇴하였다.";

            using (var ms = new MemoryStream())
                using (var writer = new SocketWriter(ms, 8))
                    using (var reader = new StreamReader(ms))
                    {
                        writer.Write("This is line 1\r\n");
                        writer.Write(str1 + "\r\n");
                        writer.Write(str2 + "\r\n");
                        writer.Write("This is line 4\r\n");

                        writer.Flush();
                        ms.Seek(0, SeekOrigin.Begin);

                        Assert.AreEqual("This is line 1", reader.ReadLine());
                        Assert.AreEqual(str1, reader.ReadLine());
                        Assert.AreEqual(str2, reader.ReadLine());
                        Assert.AreEqual("This is line 4", reader.ReadLine());
                    }
        }
Пример #13
0
        private void SendFilesList( )
        {
            string[] filePaths = Directory.GetFiles(StorageLocation);

            SocketWriter.WriteToSocket(NWStream, "Files " + String.Join(" ", filePaths));
        }