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


C# NetworkStream.Write方法代码示例

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


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

示例1: Write

        public void Write(ref NetworkStream stream)
        {
            // write OpenCount
            stream.Write(BitConverter.GetBytes(this.OpenCount), 0, 4);

            // write SignList
            stream.WriteByte((byte)this.SignList.Count);

            foreach(ushort n in this.SignList)
            {
                stream.Write(BitConverter.GetBytes(n), 0, 2);
            }
        }
开发者ID:RudyJ,项目名称:ODK-DarkEmu,代码行数:13,代码来源:BloodBibleSignInfo.cs

示例2: 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

示例3: Write

        public override void Write(NetworkStream ns)
        {
            var s = File.ReadAllText(Content);
            var ws = new WebSharpInterpiter(s, Headers, req );
            var cont = ws.Gencontent();

            {
                var hds = Headers.ToString();
                if (hds != "")
                {
                    var buf = Encoding.ASCII.GetBytes(hds + Environment.NewLine);
                    ns.Write(buf, 0, buf.Length);
                }
            }
            {
                var hds = ws.Headers.ToString();
                if (hds != "")
                {
                    var buf = Encoding.ASCII.GetBytes(hds + Environment.NewLine + Environment.NewLine);
                    ns.Write(buf, 0, buf.Length);
                }
            }
            {

                var buf = Encoding.ASCII.GetBytes(cont);
                ns.Write(buf, 0, buf.Length);
            }
        }
开发者ID:Myvar,项目名称:MyvarWeb,代码行数:28,代码来源:WebSharpResponce.cs

示例4: TCPSender

        //생성자 인자로 ServerIP와 보낼 파일의 FilePath를 받는다.
        public TCPSender(string ipAddress, int port, string FilePath, string FileName, int apikey)
        {
            try
            {
                tcpClient = new TcpClient(ipAddress, port); //TcpClient 객체 생성 및 ip와 연결
                netStream = tcpClient.GetStream(); //데이터를 보내고 받는 NetworkStream 반환
                fileStream = File.OpenRead(FilePath); //서버로 보낼 파일을 FileStream으로 부른다.

                // 파일 크기 전송
                fileLength = fileStream.Length; //파일의 크기를 저장한다.
                byte[] buffer = BitConverter.GetBytes(fileLength);
                netStream.Write(buffer, 0, buffer.Length);

                // 파일 이름, 이름 크기 전송
                byte[] filenamebuffer = System.Text.Encoding.UTF8.GetBytes(FileName);
                buffer = BitConverter.GetBytes(filenamebuffer.Length);
                netStream.Write(buffer, 0, buffer.Length);
                netStream.Write(filenamebuffer, 0, filenamebuffer.Length);

                // APIkey
                buffer = BitConverter.GetBytes(apikey);
                netStream.Write(buffer, 0, buffer.Length);

                FileSend();
                //send = new Thread(new ThreadStart(FileSend)); //send 쓰레드 생성
                //send.Start(); //쓰레드 시작으로 상태 전환
            }
            catch(Exception e)
            {

            }
        }
开发者ID:shepherd44,项目名称:SME_Window,代码行数:33,代码来源:SMESender.cs

示例5: Write

        public void Write(ref NetworkStream stream)
        {
            // write Index
            stream.Write(BitConverter.GetBytes(this.Index), 0, 4);

            // write Name
            stream.WriteByte((byte)this.Name.Length);
            byte[] _name = Encoding.ASCII.GetBytes(this.Name);
            stream.Write(_name, 0, _name.Length);
        }
开发者ID:RudyJ,项目名称:ODK-DarkEmu,代码行数:10,代码来源:InstanceDungeonInfo.cs

示例6: Write

 public override void Write(NetworkStream ns)
 {
     {
         var buf = Encoding.ASCII.GetBytes(Headers.ToString() + Environment.NewLine + Environment.NewLine);
         ns.Write(buf, 0, buf.Length);
     }
     {
         var buf = Encoding.ASCII.GetBytes(Content);
         ns.Write(buf, 0, buf.Length);
     }
 }
开发者ID:Myvar,项目名称:MyvarWeb,代码行数:11,代码来源:StringResponce.cs

示例7: AddPermission

        /// <summary>
        /// 添加权限
        /// </summary>
        /// <param name="dataStream"></param>
        /// <param name="in_message"></param>
        /// <param name="newClientInfo"></param>
        /// <returns></returns>
        public static Boolean AddPermission(NetworkStream dataStream, Message in_message, ClientInfo newClientInfo)
        {
            Message out_message = new Message();

            //登陆确认命令
            out_message.Command = Message.CommandHeader.AddPermission;

            //从输入信息中获取用户名、密码
            string name = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[0];
            string projectid = Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[1];
            int permissionlevel = Convert.ToInt32(Encoding.Unicode.GetString(in_message.MessageBody).Split(':')[2]);

            //用户名密码校验
            Boolean isUserExisted = UserBussinessManager.UserExisted(name);
            if (!isUserExisted)//消息体需要根据数据库检索结果//同时初始化permission
            {//用户不存在
                Console.WriteLine("添加权限:User doesn't existed!");
                out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_NOTEXISTED);
                //打包输出信息,将输出信息写入输出流
                dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength);
                return false;
            }
            else
            {
                Boolean isPermissionExisted = PermissionExisted(name, projectid, permissionlevel);
                if (isPermissionExisted)
                {//权限已经存在
                    out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_EXISTED);
                    Console.WriteLine("添加权限:权限已经存在!");
                    //打包输出信息,将输出信息写入输出流
                    dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength);
                    return false;
                }
                else
                {
                    Console.WriteLine("添加权限:准备添加权限");
                    if (Database.insertPermission(name, projectid, permissionlevel))
                    {
                        out_message.MessageBody = Encoding.Unicode.GetBytes(Constants.M_SUCCEED);
                        Console.WriteLine("添加权限:" + name + " " + projectid + " " + permissionlevel.ToString() + "权限添加成功!");
                        //打包输出信息,将输出信息写入输出流
                        dataStream.Write(out_message.ToBytes(), 0, out_message.MessageLength);

                        return true;
                    }
                    return false;
                }
            }
        }
开发者ID:qinguan,项目名称:casree,代码行数:56,代码来源:PermissionBussinessManager.cs

示例8: Flush

 public override void Flush(NetworkStream ns)
 {
     MinecraftStream read = new MinecraftStream();
     read.WriteVarInt(KeepAliveID);
     var buf = read.Flush(ID);
     ns.Write(buf, 0, buf.Length);
 }
开发者ID:Myvar,项目名称:MyvarCraft,代码行数:7,代码来源:KeepAlive.cs

示例9: Client

        public Client(Common.ServerConfig config, NameValueCollection appSettings, int myID, bool receiveOnly)
            : base(appSettings)
        {
            ClientRetryTime = Convert.ToInt32(appSettings["ClientRetryTime"]);

            tcpClient = AttemptTCPConnect(config);
            ns = tcpClient.GetStream();

            //give them our id
            Console.WriteLine("Sending id: {0}", myID);
            byte[] buffer = BitConverter.GetBytes(myID);
            ns.Write(buffer, 0, 4);
            Console.WriteLine("Sent id");

            TCPThreadState TCPState = new TCPThreadState(myID, ns);

            Thread receiveThread = new Thread(ReceiveThread);
            receiveThread.Start(TCPState);

            if (!receiveOnly)
            {
                Thread broadcastThread = new Thread(BroadcastThread);
                broadcastThread.Start(TCPState);
            }
        }
开发者ID:jamesjrg,项目名称:taipan,代码行数:25,代码来源:Client.cs

示例10: HandleRequest

        private void HandleRequest(object conSocket)
        {
            var connectionSocket = (Socket)conSocket;
            Stream ns = new NetworkStream(connectionSocket);
            var sr = new StreamReader(ns);
            var sw = new StreamWriter(ns);

            try
            {
                var line = "dummy";
                var requestRaw = "";
                while (line != "\r\n")
                {
                    line = sr.ReadLine() + "\r\n";
                    requestRaw += line;
                }

                var request = new HttpRequest(requestRaw);
                var response = new HttpResponse(request.Uri);

                StopServer = request.MessageType == "EXIT";

                var responseBytes = response.ToBytes();
                ns.Write(responseBytes, 0, responseBytes.Length);
            }
            finally
            {
                sw.Close();
                sr.Close();
                ns.Close();
                connectionSocket.Close();
            }
        }
开发者ID:FilipDusek,项目名称:HTTP-server,代码行数:33,代码来源:HTTPServer.cs

示例11: 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

示例12: ServerConnection

 private void ServerConnection(NetworkStream stream)
 {
     int RecievedSymbols = 0;
     byte[] recieved = new byte[2048];
     byte[] to_send = new byte[2048];
     string task = "";
     while ( (RecievedSymbols = stream.Read(recieved, 0, recieved.Length)) > 0 )
     {
         task = Resize(recieved);
         task = TaskToDo(task);
         Console.WriteLine(task);
         if (task.Equals("closed -1"))
         {
             to_send = Encoding.ASCII.GetBytes(task);
             stream.Write(to_send, 0, to_send.Length);
             client.Close();
             return;
         }
         else
         {
             to_send = Encoding.ASCII.GetBytes(task);
             stream.Write(to_send, 0, to_send.Length);
         }
        Array.Clear(to_send, 0, to_send.Length);
        Array.Clear(recieved, 0, recieved.Length);
     }
 }
开发者ID:DimasBro0110,项目名称:Big_File_Processor,代码行数:27,代码来源:Program.cs

示例13: Flush

 public override void Flush(NetworkStream ns)
 {
     MinecraftStream Write = new MinecraftStream();
     Write.WriteLong(Payload);
     var buf = Write.Flush(ID);
     ns.Write(buf, 0, buf.Length);
 }
开发者ID:Myvar,项目名称:MyvarCraft,代码行数:7,代码来源:Pong.cs

示例14: Post

 public void Post(NetworkStream stream)
 {
     StreamWriter writer = new StreamWriter(stream);
     writer.WriteLine("{0} {1}\r\nServer: {2}\r\nContent-Type: {3}\r\nAccept-Ranges: bytes\r\nContent-Length: {4}\r\n",
         HttpServer.VERSION, status, HttpServer.Name, mime, data.Length);
     stream.Write(data, 0, data.Length);
 }
开发者ID:MARTIN-HERO,项目名称:HttpFileServerDemo,代码行数:7,代码来源:Response.cs

示例15: Main

        static void Main(string[] args)
        {
            Console.Write("Please enter your name: ");
            userName = Console.ReadLine();
            client = new TcpClient();
            try
            {
                client.Connect(host, port);
                stream = client.GetStream();

                string message = userName;
                byte[] data = Encoding.Unicode.GetBytes(message);
                stream.Write(data, 0, data.Length);

                Thread receiveThread = new Thread(new ThreadStart(ReceiveMessage));
                receiveThread.Start();
                Console.WriteLine("Wellcome, {0}", userName);
                SendMessage();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Disconnect();
            }
        }
开发者ID:AntonRozhanskiy,项目名称:LearningApps,代码行数:28,代码来源:Program.cs


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