当前位置: 首页>>代码示例>>C#>>正文


C# Socket.GetStream方法代码示例

本文整理汇总了C#中Socket.GetStream方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.GetStream方法的具体用法?C# Socket.GetStream怎么用?C# Socket.GetStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Socket的用法示例。


在下文中一共展示了Socket.GetStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Listen

        protected async Task Listen(Socket socket) {
            Stream ioStream = socket.GetStream();
            StreamReader reader = new StreamReader(ioStream);
            StreamWriter writer = new StreamWriter(ioStream);

            await writer.WriteLineAsync(FtpResponse.PositiveCompletionReply.ServiceReady.ToString());
            await writer.FlushAsync();
            string command;
            while (true) {
                string result = await RunCommand(await reader.ReadLineAsync());
                await writer.WriteLineAsync(result);
                await writer.FlushAsync();
            }
        }
开发者ID:XuPeiYao,项目名称:IronFtpService,代码行数:14,代码来源:FtpSocket.cs

示例2: SendMessageFromSocket

        static void SendMessageFromSocket(int port)
        {
            // Буфер для входящих данных
            byte[] bytes = new byte[1024];

            // Соединяемся с удаленным устройством

            // Устанавливаем удаленную точку для сокета
            IPHostEntry ipHost = Dns.GetHostEntry("localhost");
            IPAddress ipAddr = ipHost.AddressList[0];
            IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, port);

            Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            // Соединяем сокет с удаленной точкой
            sender.Connect(ipEndPoint);

            string path = Console.ReadLine();

            NetworkStream stream = sender.GetStream();
            BinaryFormatter format = new BinaryFormatter();
            byte[] buf = new byte[1024];
            int count;
            int process = 0;
            int endprocess = 100;
            FileStream fs = new FileStream("C:\\" + path, FileMode.Open);
            BinaryReader br = new BinaryReader(fs);
            long k = fs.Length;
            format.Serialize(stream, path);
            format.Serialize(stream, k.ToString());
            while ((count = br.Read(buf, 0, 1024)) > 0)
            {
                process++;
                Console.Clear();
                Console.Write(((process * 1024) * 100) / fs.Length + "%");
                format.Serialize(stream, buf);
            }
            Console.WriteLine("\nSuccessfully send");
            stream.Close();

            // Освобождаем сокет
            sender.Shutdown(SocketShutdown.Both);
            sender.Close();
        }
开发者ID:sbst,项目名称:code,代码行数:44,代码来源:Program.cs


注:本文中的Socket.GetStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。