基于TCP网络通信的自动升级程序源码分析-客户端连接服务器

时间:2015-01-30 09:01:05   收藏:0   阅读:196
服务器开始监听
            //从配置文件获取要监听的IP和端口
            string strIP = System.Configuration.ConfigurationManager.AppSettings["IPAddress"];
            int port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
            //开始监听
            Connection.StartListening(ConnectionType.TCP, new IPEndPoint(IPAddress.Parse(strIP), port));
         
            AddLineToLog("初始化完成,正在监听:");

 

 
客户端连接服务器
       //连接信息对象
        public ConnectionInfo connInfo = null;
        //连接对象
        Connection newTcpConnection;


        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //给连接信息对象赋值
            //为了简单直接从文本框获取,也可以设置为从app.config配置文件获取IP和端口
            connInfo = new ConnectionInfo(txtIP.Text, int.Parse(txtPort.Text));

            //根据连接信息对象,启动一个到服务器端的连接,如果不成功,会弹出异常信息
            newTcpConnection = TCPConnection.GetConnection(connInfo);

            button1.Enabled = false;
            button1.Text = "连接成功";
 
        }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!