【发布时间】:2021-06-13 20:07:53
【问题描述】:
我已经按照我的想法做了所有事情。如果我在云上运行它,我的应用程序就可以工作。
我运行的命令:
gcloud 构建提交 --tag gcr.io/****
gcloud run deploy *** --region us-central1 --platform managed --image gcr.io/t*** --allow-unauthenticated --port=26951
Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk
COPY . /app
WORKDIR /app
RUN dotnet publish -c Release -o out
ENTRYPOINT ["dotnet", "Test.dll"]
程序:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace Server
{
class Program
{
private static TcpListener tcpListener;
public static void Main(string[] args)
{
tcpListener = new TcpListener(IPAddress.Any, 26951);
tcpListener.Start();
tcpListener.BeginAcceptTcpClient(TCPConnectCallback, null);
}
private static void TCPConnectCallback(IAsyncResult _result)
{
TcpClient _client = tcpListener.EndAcceptTcpClient(_result);
}
}
}
CSProj:
<Project Sdk="***">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>
所有这些都在同一个位置
【问题讨论】:
-
您为什么希望您的代码与 Cloud Run 一起使用? Cloud Run 需要对 HTTP 请求的响应。除非您遗漏其他代码,否则您的代码只会关闭连接。
-
@JohnHanley 哇,谢谢。所以我想我的问题是我应该在哪里部署这段代码呢?或者这在 Google Cloud 上是不可能的?
-
用更多细节编辑您的问题。您的代码除了听、接受和关闭之外什么都不做。
-
@JohnHanley 我认为这是多余的。这是我所有的代码:github.com/robin271/Server \ 我仍然需要继续努力,但我认为这个项目的要点已经传达;它应该将每个传入的 tcp 连接分配给单个服务器。
标签: c# docker google-cloud-platform