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


C# NetworkStream.Flush方法代码示例

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


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

示例1: Start

        /// <summary>
        /// Start the listener for incoming messages
        /// </summary>
        public void Start()
        {
            tcpListener = new TcpListener(System.Net.IPAddress.Any, this.port);
            tcpListener.Start();
            Console.WriteLine("Server Started") ;
            this.IsListening = true;

            try
            {
                while (isListening)
                {
                    Console.WriteLine("Server listening...");
                    Socket socketForClient = tcpListener.AcceptSocket();
                    Console.WriteLine("Client connected");
                    NetworkStream networkStream = new NetworkStream(socketForClient);

                    BinaryFormatter bf = new BinaryFormatter();
                    Object message = (RemoteMessage)bf.Deserialize(networkStream);

                    networkStream.Flush();

                    interpretMessage((RemoteMessage)message);

                    socketForClient.Disconnect(true);
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString()) ;
            }
        }
开发者ID:psweeney-YU,项目名称:NEVP-conveyor,代码行数:34,代码来源:RemoteServer.cs

示例2: Send

        //Méthode statique pour l'envoi et la réception
        public void Send(Paquet paquet, NetworkStream stream)
        {
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(stream, paquet);
            stream.Flush();
        }
开发者ID:Cs2iLeSwag,项目名称:Projet-Hermes,代码行数:8,代码来源:TypePaquet.cs

示例3: Write

        public void Write(NetworkStream stream)
        {
            stream.WriteByte((byte)this.Type);

            StreamHelper.WriteDouble(stream, this.Unknown1);
            StreamHelper.WriteDouble(stream, this.Unknown2);
            StreamHelper.WriteDouble(stream, this.Unknown3);
            StreamHelper.WriteFloat(stream, this.Unknown4);
            StreamHelper.WriteInt(stream, Unknown5.Count);

            int i = (int)this.Unknown1;
            int j = (int)this.Unknown2;
            int k = (int)this.Unknown3;
            sbyte j1;
            for (IEnumerator<ChunkPosition> iter = this.Unknown5.GetEnumerator(); iter.MoveNext(); stream.WriteByte(j1))
            {
                ChunkPosition chunkpos = iter.Current;
                int l = chunkpos.X - i;
                int i1 = chunkpos.Y - j;
                j1 = (sbyte)(chunkpos.Z - k);
                stream.WriteByte((byte)l);
                stream.WriteByte((byte)i1);
            }

            stream.Flush();
        }
开发者ID:tgrochowicz,项目名称:mcsharpbot,代码行数:26,代码来源:Explosion.cs

示例4: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                readData = "Connected to Chat Server ...";
                msg();
                clientSocket.Connect("127.0.0.1", 8888);
                serverStream = clientSocket.GetStream();

                byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox2.Text + "$");
                serverStream.Write(outStream, 0, outStream.Length);
                serverStream.Flush();

                Thread ctThread = new Thread(getMessage);
                ctThread.Start();

                if(strUser == null)
                {
                    strUser = textBox2.Text;
                    Registry.SetValue(keyName, "user", strUser);
                }

                buttonSend.Enabled = true;
            }
            catch(Exception ex)
            {
                buttonSend.Enabled = false;
            }
        }
开发者ID:Ikthios,项目名称:Communication-System,代码行数:29,代码来源:MainForm.cs

示例5: Write

        public void Write(NetworkStream stream)
        {
            stream.WriteByte((byte)this.Type);
            StreamHelper.WriteString(stream, this.Username);

            stream.Flush();
        }
开发者ID:tgrochowicz,项目名称:mcsharpbot,代码行数:7,代码来源:Handshake.cs

示例6: send

 private void send(NetworkStream networkStream, Byte[] bufferOut)
 {
     //------------------------------------------------Send message
     networkStream.Write(bufferOut, 0, bufferOut.Length);
     networkStream.Flush();
     base.ByteSent += bufferOut.Length;
 }
开发者ID:rhalf,项目名称:AtsGpsSocket,代码行数:7,代码来源:TqatCommandTcpManager.cs

示例7: button2_Click

        private void button2_Click(object sender, EventArgs e)

        {

            readData = "Conected to Chat Server ...";

            msg();

            clientSocket.Connect("127.0.0.1", 8888);

            serverStream = clientSocket.GetStream();



            byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox3.Text + "$");

            serverStream.Write(outStream, 0, outStream.Length);

            serverStream.Flush();



            Thread ctThread = new Thread(getMessage);

            ctThread.Start();

        }
开发者ID:Mortion,项目名称:Uses,代码行数:27,代码来源:Form1.cs

示例8: SendString

 public static void SendString(NetworkStream client, string s)
 {
     var bytes = Encoding.UTF8.GetBytes(s);
     client.Write(BitConverter.GetBytes(bytes.Length), 0, 4);
     client.Write(bytes, 0, bytes.Length);
     client.Flush();
 }
开发者ID:vlthr,项目名称:hearthomaton,代码行数:7,代码来源:NetworkUtil.cs

示例9: sendMessage

        /** 
         * Function to send a message to the server
         * \param stream - The stream to write to
         * \param msg - The message to send
         * \return - Retun true on success, false on failure
         */
        private bool sendMessage(NetworkStream stream, Message msg)
        {
            string json = JsonConvert.SerializeObject(msg);

            using (MemoryStream mstream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(mstream))
                {
                    byte[] encodedJson = Encoding.UTF8.GetBytes(json);
                    writer.Write(hostToBig_i32(encodedJson.Length));
                    writer.Write(encodedJson);
                }

                byte[] request = mstream.ToArray();
                try
                {
                    stream.Write(request, 0, request.Length);
                    stream.Flush();
                }
                catch(SocketException ex)
                {
                    Message emsg = new Message("error_socket", null);
                    emsg.AddParameter("error_code", ex.ErrorCode);
                    emsg.AddParameter("message", ex.Message);                    
                    recvq.Enqueue(emsg);
                    return false;
                }
            }

            return true;
        }
开发者ID:corebob,项目名称:crash,代码行数:37,代码来源:Burn_NetService_IO.cs

示例10: send

 public virtual void send(NetworkStream ns)
 {
     if (data == null) {
         getBytes ();
     }
     ns.Write (data, 0, data.Length);
     ns.Flush ();
 }
开发者ID:kon0524,项目名称:Ev3Theta,代码行数:8,代码来源:PtpPacket.cs

示例11: Write

        public void Write(NetworkStream stream)
        {
            stream.WriteByte((byte)this.Type);

            stream.WriteByte((OnGround ? (byte)1 : (byte)0));

            stream.Flush();
        }
开发者ID:tgrochowicz,项目名称:mcsharpbot,代码行数:8,代码来源:Flying.cs

示例12: Write

        public void Write(NetworkStream stream)
        {
            stream.WriteByte((byte)this.Type);

            stream.WriteByte(this.WindowId);

            stream.Flush();
        }
开发者ID:tgrochowicz,项目名称:mcsharpbot,代码行数:8,代码来源:WindowClose.cs

示例13: Write

        public void Write(NetworkStream stream)
        {
            stream.WriteByte((byte)this.Type);

            StreamHelper.WriteShort(stream, this.PlayerHealth);

            stream.Flush();
        }
开发者ID:tgrochowicz,项目名称:mcsharpbot,代码行数:8,代码来源:Health.cs

示例14: Write

        public void Write(NetworkStream stream)
        {
            stream.WriteByte((byte)this.Type);

            StreamHelper.WriteInt(stream, this.EntityID);

            stream.Flush();
        }
开发者ID:tgrochowicz,项目名称:mcsharpbot,代码行数:8,代码来源:Entity.cs

示例15: AsyncProcessResponse

 public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state,
                                   IMessage msg, ITransportHeaders headers, Stream responseStream)
 {
     ClientConnection connection = (ClientConnection)state;
     NetworkStream stream = new NetworkStream (connection.Client);
     UnixMessageIO.SendMessageStream (stream, responseStream, headers, connection.Buffer);
     stream.Flush ();
     stream.Close ();
 }
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:9,代码来源:UnixServerTransportSink.cs


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