简体   繁体   English

如何将C#套接字服务器应用程序部署到Azure VM? 这真的是个好主意吗?

[英]How can I deploy my C# Socket Server app into an Azure VM ? Is it really a good idea?

I had an idea, and am trying to upload data from a Netduino to a SQL DB hosted in an Azure VM. 我有一个主意,正在尝试将数据从Netduino上传到Azure VM中托管的SQL DB。 After struggling with WCF, I have just written a simple app in C# that processes requests through Sockets (code below) and does the job -works fine on my machine/LAN. 经过WCF的努力后,我刚刚用C#编写了一个简单的应用程序,该应用程序通过Socket处理请求(以下代码),并在我的机器/ LAN上正常工作。 Since I still don't know much about 因为我还是不太了解

Azure VMs, how can I expose an IP/port to the outside world in such a way that my client application reaches the server part successfully? Azure VM, 如何以一种使客户端应用程序成功到达服务器部分的方式向外部公开IP /端口? Currently I can't make the Azure VM to listen to the outside world. 目前,我无法使Azure VM收听外界。 I have created an endpoint (with a name, TCP protocol, same public and private ports and checked 'enable direct server return'. To try it, I shutdown the firewall and tried it, from outside, to no avail. 我已经创建了一个端点(具有名称,TCP协议,相同的公共端口和私有端口,并选中了“启用直接服务器返回”。要尝试这样做,我关闭了防火墙,并尝试从外部进行,无济于事。

Can a listener on that port be considered a secure solution? 可以将该端口上的侦听器视为安全解决方案吗?

For the sake of simplicity I thought of Sockets, but is it really a good idea ? 为了简单起见,我想到了Sockets,但这真的是一个好主意吗? Would you guys do differently and still keep it simple as this ? 你们会做不同的事情,并且仍然保持这种简单吗?

...
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 3211);
server.Bind(localEndPoint);
server.Listen(Int32.MaxValue);
while (true)
{
    Socket clientSocket = server.Accept();
    new ProcessClientRequest(clientSocket);
}
...


public ProcessClientRequest(Socket clientSocket)
{
    m_clientSocket = clientSocket;
    new Thread(ProcessRequest).Start();
}

private void ProcessRequest()
{
    const Int32 c_microsecondsPerSecond = 1000000;
    using (m_clientSocket)
    {
        Byte[] buffer = new Byte[1024];
        string lastRead;
        if (m_clientSocket.Poll(5 * c_microsecondsPerSecond, SelectMode.SelectRead))
        {
            if (m_clientSocket.Available == 0)
                 return;
            Int32 bytesRead = m_clientSocket.Receive(buffer, m_clientSocket.Available, SocketFlags.None);
            // Return a key to the client.
            lastRead = WriteDataToDB(System.Text.Encoding.UTF8.GetString(buffer).Replace("\0", string.Empty));
            m_clientSocket.Send(Encoding.UTF8.GetBytes(lastRead));
        }
    }
}    

Have you checked your VM's endpoint settings on https://manage.windowsazure.com/ ? 您是否在https://manage.windowsazure.com/上检查了VM的端点设置? Adding a rule there should allow anyone to connect to <vm-dns-name>.cloudapp.net:<public-port> . 在此处添加规则应允许任何人连接到<vm-dns-name>.cloudapp.net:<public-port> That's the DNS name, not the VM name. 那是DNS名称,而不是VM名称。 My Meteor app didn't need the direct server return feature. 我的Meteor应用程序不需要直接服务器返回功能。

A sufficiently hard hashing and encryption layer should be secure enough, provided the customers know your public key's fingerprint because Certificate Authorities can be compromised . 如果客户知道您的公钥的指纹,因为证书颁发机构可能会受到损害 ,那么足够硬的哈希和加密层应该足够安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM