clienttcp.cs

来自「8583包打包解包小应用」· CS 代码 · 共 48 行

CS
48
字号
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace My8583App
{
    public delegate void MyDelegate(string temp);
    class ClientTcp
    {
        //设置网络流局部对象
        private NetworkStream ns;

        //声明类型为MyDelegate的事件MyEvent
        public event MyDelegate MyEvent;

        //构造函数中接收参数以初始化
        public ClientTcp(NetworkStream ns)
        {
            this.ns = ns;
        }

        //服务器端线程所调用的方法
        public void TcpThread()
        {

            //获得相关的封装流
            StreamReader sr = new StreamReader(ns);
            string temp = sr.ReadLine();
            

            //接收到客户端消息后触发事件将消息回传
            MyEvent(temp);
            StreamWriter sw = new StreamWriter(ns);

            //转换为大写后发送消息给客户端
            sw.WriteLine(temp.ToUpper());
            sw.Flush();
            sw.Close();
            sr.Close();
        }


    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?