NET与Python通信

NET与Python通信,python,asp.net,Python,Asp.net,我试图从asp.net网站向运行在raspberry pi上的python文件发送消息。如果这是pi上python的代码 导入套接字 serversocket=socket.socket(socket.AF\u INET,socket.SOCK\u流) 绑定(('localhost',8089)) serversocket.listen(5)#成为服务器套接字,最多5个连接 尽管如此: 连接,地址=serversocket.accept() buf=connection.recv(64) 如果l

我试图从asp.net网站向运行在raspberry pi上的python文件发送消息。如果这是pi上python的代码

导入套接字
serversocket=socket.socket(socket.AF\u INET,socket.SOCK\u流)
绑定(('localhost',8089))
serversocket.listen(5)#成为服务器套接字,最多5个连接
尽管如此:
连接,地址=serversocket.accept()
buf=connection.recv(64)
如果len(buf)>0:
打印基本单位
打破
我只是需要一些开始的帮助。假设我知道运行Python代码的Raspberry Pi的外部和内部ip地址,那么如何使用ASP.NET开始编写代码呢

我会使用
socket.io
还是其他什么?在ASP.NET网站和Python之间进行通信的最佳想法或方法是什么?我知道这个问题很笼统,但我只需要一些帮助就可以开始正确的方向。

(编辑)改进的ASP.NET代码:

protected void Page_Load(object sender, EventArgs e)
{

    TcpClient client = new TcpClient("192.168.1.107", 8012);

    // Translate the passed message into ASCII and store it as a Byte array.
    Byte[] data = System.Text.Encoding.ASCII.GetBytes("Hello There");

    // Get a client stream for reading and writing.
    //  Stream stream = client.GetStream();

    NetworkStream stream = client.GetStream();

    // Send the message to the connected TcpServer. 
    stream.Write(data, 0, data.Length);

    // Receive the TcpServer.response.

    // Buffer to store the response bytes.
    data = new Byte[256];

    // String to store the response ASCII representation.
    String responseData = String.Empty;

    // Read the first batch of the TcpServer response bytes.
    Int32 bytes = stream.Read(data, 0, data.Length);
    responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    Response.Write(responseData);

    // Close everything.
    stream.Close();
    client.Close();
    }
}

正在工作,我现在正在使用。有更好的选择吗?谢谢你的回复。:)

如果Python服务器直接在套接字上侦听(而不是使用HTTP之类的协议),那么我认为直接从.NET在套接字上连接将是一个不错的选择。你试过了吗?为什么用插座?试试
wsgiref
,非常基本。