如何使用TCP将变量从ASP.Net发送到IP地址

时间:2011-06-14 07:02:25

标签: .net asp.net variables tcp ip

我正在为我的项目开发一个网站。我是Asp.net和这个论坛的新手。 我的项目是控制网站的一个主管。

我正在使用网络模块将我的微控制器与网络服务器连接起来。 我想做的是从ASP.net发送变量到网络模块的IP地址。

非常感谢能帮助我的每个人 这是ASP代码(page.aspx.cs)。

    public partial class VirtualRemote : System.Web.UI.Page
    {


        protected void Page_Load(object sender, EventArgs e)
        {



        }


        protected void Button1_Click(object sender, EventArgs e)
        {

        // when this button is click i want to send a variable example "A"
          to network module IP example 192.168.1.2. so network module can pass the
          variable to microC , i already have microC program to receive from network  module  


        }

}

1 个答案:

答案 0 :(得分:2)

Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
clientSocket.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.2"), PORT_NUMBER));

// Send the file name.
var A = "TEST STRING";
clientSocket.Send(Encoding.UTF8.GetBytes(A));

有关Socket

的更多信息