【问题标题】:How to send a variable from ASP.Net to an IP address using TCP如何使用 TCP 将变量从 ASP.Net 发送到 IP 地址
【发布时间】:2011-09-14 11:17:46
【问题描述】:

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

我正在使用网络模块将我的微控制器与网络服务器连接起来。 我想要做的是将变量从 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  


        }

}

【问题讨论】:

  • 什么协议类型 tcp 或 udp?
  • 为什么不在Button1_Click 方法中使用Socket 实例并将需要发送的内容发送到网络感知微控制器?

标签: .net asp.net variables tcp ip


【解决方案1】:
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类

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 2017-12-12
    • 2013-06-23
    • 1970-01-01
    相关资源
    最近更新 更多