Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有C#严重性和#x9的Winsock;代码错误:名称';数据输入';在当前上下文中不存在_C#_Server_Client_Winsock - Fatal编程技术网

具有C#严重性和#x9的Winsock;代码错误:名称';数据输入';在当前上下文中不存在

具有C#严重性和#x9的Winsock;代码错误:名称';数据输入';在当前上下文中不存在,c#,server,client,winsock,C#,Server,Client,Winsock,我不熟悉c#编码,我的项目是使用Winsock控件连接服务器和客户端。我正是在做这个程序来连接服务器和客户端 表格: 代码: 错误 当前上下文中不存在名称“DataInput” 我似乎无法通过搜索web找到解决此问题的方法。请帮助我:(在表单上创建一个名为“DataInput”的文本框。创建一个名为“DataInput”的文本框在您的表单上。似乎DataInput是用于发送数据的编辑控件的名称。您可能在表单上给它命名了其他名称。@JamieMeyer抱歉,我无法理解“其他名称”意味着我需要使用

我不熟悉c#编码,我的项目是使用Winsock控件连接服务器和客户端。我正是在做这个程序来连接服务器和客户端

表格:

代码:

错误

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


我似乎无法通过搜索web找到解决此问题的方法。请帮助我:(

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

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

似乎DataInput是用于发送数据的编辑控件的名称。您可能在表单上给它命名了其他名称。@JamieMeyer抱歉,我无法理解“其他名称”意味着我需要使用什么来代替DataInput。我再次查看了代码。标签“Get data”下面的大控件应命名为DataInput。@jamieMeyer感谢您的宝贵命令,它显示了连接的数据,并提供了我在客户端输入的数据(请参阅问题中的屏幕摘要)但是请告诉我如何使用服务器表单。如果我需要创建新表单?或者我使用bin->debug->server.exe?但它不起作用,我会尝试。请告诉我如何访问服务器表单。看起来DataInput是用于发送数据的编辑控件的名称。您可能在表单上为它命名了其他名称。@JamieMeyer抱歉,我无法使用它stand“Other”是指我需要使用的东西,而不是DataInput。我再次查看了代码。标签“Get Data”下面的大控件应命名为DataInput。@jamieMeyer感谢您的宝贵命令它显示连接的数据,并提供我在客户端输入的数据(请参阅我问题中的简短屏幕)但是请告诉我如何使用服务器表单。如果我需要创建新表单?或者我使用bin->debug->server.exe?但它不起作用,我会尝试。请告诉我如何访问服务器表单。
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;
        }
    }
}