Пример #1
0
        protected override void MainCore()
        {
            IPAddress ip = GetServerIP();
            using (TcpClient client = new TcpClient())
            {
                client.Connect(ip, PORT);
                using (Stream stream = client.GetStream())
                {
                    using (SyncReader reader = new SyncReader(stream))
                    {
                        using (SyncWriter writer = new SyncWriter(stream))
                        {
                            SyncCode code = SyncCode.Error;

                            // 1. Handshake
                            writer.Write(SyncCode.Handshake);
                            writer.Write(HANDSHAKE);
                            code = reader.ReadCode();
                            VerifyCode(code, SyncCode.Ok, reader, writer);

                            // 2. Files
                            foreach (String file in Directory.GetFiles(_folder, _mask))
                            {
                                writer.Write(SyncCode.File);
                                writer.Write(file);

                                code = reader.ReadCode();
                                if (code == SyncCode.Cancel)
                                    continue;

                                VerifyCode(code, SyncCode.Ok, reader, writer);
                            }

                            writer.Write(SyncCode.Cancel);
                        }
                    }
                }
            }
        }
Пример #2
0
        protected override void MainCore()
        {
            TcpListener listener = new TcpListener(IPAddress.Any, PORT);
            listener.Start();
            using (TcpClient client = listener.AcceptTcpClient())
            {
                using (Stream stream = client.GetStream())
                {
                    using (SyncReader reader = new SyncReader(stream))
                    {
                        using (SyncWriter writer = new SyncWriter(stream))
                        {
                            SyncCode code = SyncCode.Error;

                            code = reader.ReadCode();
                            VerifyCode(code, SyncCode.Handshake, reader, writer);
                            String handshake = reader.ReadString();
                            VerifyHandshake(handshake, HANDSHAKE, writer);

                            writer.Write(SyncCode.Ok);

                            while (true)
                            {
                                code = reader.ReadCode();
                                if (code == SyncCode.Cancel)
                                    break;

                                VerifyCode(code, SyncCode.File, reader, writer);
                                String file = reader.ReadString();
                                writer.Write(SyncCode.Cancel);
                            }
                        }
                    }
                }
            }
        }