首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有C#严重性代码错误的Winsock :名称'DataInput‘在当前上下文中不存在

带有C#严重性代码错误的Winsock :名称'DataInput‘在当前上下文中不存在
EN

Stack Overflow用户
提问于 2016-04-27 05:22:28
回答 1查看 112关注 0票数 1

我刚开始使用c#进行编码,我的项目是使用Winsock控件连接服务器和客户端。我正做这个程序http://www.go4expert.com/articles/winsock-c-sharp-t3312/连接服务器和客户端。

表格:在这里输入图像描述

代码:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Winsock
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.w1.Error += new AxMSWinsockLib.DMSWinsockControlEvents_ErrorEventHandler(this.w1_Error);
            this.w1.ConnectEvent += new System.EventHandler(this.w1_ConnectEvent);
            this.w1.DataArrival += new AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEventHandler(this.w1_DataArrival);
        }
        Boolean isConnect = false;
        private void w1_ConnectEvent(object sender, EventArgs e)
        {
            DataInput.Text += "\n - Connect Event : " + w1.RemoteHostIP;
            isConnect = true;
        }

        public void w1_Error(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ErrorEvent e)
        {
            DataInput.Text += "\n- Error : " + e.description;
            isConnect = false;
        }

        private void w1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
        {
            String data = "";      
            Object dat = (object)data;
            w1.GetData(ref dat);
            data = (String)dat;
            DataInput.Text += "\nServer - " + w1.RemoteHostIP + " : " + data;
        }

        private void send_Click(object sender, EventArgs e)
        {
            try
            {
                if (isConnect)
                {
                    w1.SendData(SendText.Text);

                    DataInput.Text += "\nClent(You ;-) : " + SendText.Text;

                    SendText.Text = "";
                }
                else
                    MessageBox.Show("You are not connect to any host ");
            }
            catch (AxMSWinsockLib.AxWinsock.InvalidActiveXStateException g)
            {
                DataInput.Text += "\n" + g.ToString();
            }
            catch (Exception ex)
            {
                DataInput.Text += "\n" + ex.Message;
            }
        }

        private void disconnect_Click(object sender, EventArgs e)
        {
            w1.Close();
            w1.LocalPort = Int32.Parse(portText.Text);
            w1.Listen();
            DataInput.Text += "\n - Disconnected";
        }

        private void Connect_Click(object sender, EventArgs e)
        {
            try
            {
                w1.Close(); 
                w1.Connect(IPText.Text, portText.Text);

            }
            catch (System.Windows.Forms.AxHost.InvalidActiveXStateException g)
            {
                DataInput.Text += "\n" + g.ToString();
            }
        }

        private void w1_ConnectionRequest(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent e)
        {
            if (isConnect == true)
            {
                w1.Close();
            }
            w1.Accept(e.requestID);
            isConnect = true;
            DataInput.Text += "\n - Client Connected :" + w1.RemoteHostIP;
        }
    }
}

错误

名称“DataInput”在当前上下文中不存在

我似乎无法通过搜索网络找到解决这个问题的方法--请帮助我:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-27 07:13:40

在表单上创建一个名为"DataInput“的文本框。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36880947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档