小编Tob*_*rto的帖子

使用 Socket 将数据从 [Python 客户端] 发送到 [C# 服务器]

我想使用简单的套接字应用程序将字节数据从 Python 客户端发送到 C# 服务器。C# 服务器与 C# 客户端一起工作正常!

但是当我尝试使用 Python Socket 将数据发送到 C#-Server 时,数据永远不会到达。

我不太习惯 Python,有人可以检查我的代码并提示我如何在我的 c# 服务器中接收数据吗?

我在代码中犯了错误吗?这可能是将字节数据从 Python 发送到 C# 的错误方式吗?有更好的解决方案吗?

Python客户端:

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 5005
MESSAGE = b'Hello World !'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE)
s.close()
Run Code Online (Sandbox Code Playgroud)

C#服务器:

private void start()
{
    Console.WriteLine("Port: ");
    _port = Console.ReadLine();
    byte[] buffer = new Byte[1024];
    IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), int.Parse(_port));
    Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

    try
    {
        listener.Bind(localEndPoint);
        listener.Listen(10);

        while (true)
        { …
Run Code Online (Sandbox Code Playgroud)

c# python sockets tcp python-3.x

5
推荐指数
0
解决办法
2891
查看次数

创建嵌套数据(JSON或数组)

我有以下结构的零件清单:

level | description
    0 | sfg
    1 | sdf
    2 | asdisg
    3 | sidjhf
    4 | wefdsj
    4 | asdfg
    4 | sgfd
    4 | sdg
    3 | sfg
    3 | fdg
    4 | sdfg
    4 | sdsfd
    4 | sdf
    4 | sdf
    2 | adf
    3 | sdfg
    4 | sdg
    4 | sdf
    4 | sdf
    4 | sdf
    1 | shfg
    2 | ijsd
    3 | ijsd
    4 | sdf
    4 | sdf
Run Code Online (Sandbox Code Playgroud)

我需要将零件列表转换为这样的层次结构文件夹结构(在嵌套JSON中更可取): …

javascript json

5
推荐指数
0
解决办法
71
查看次数

标签 统计

c# ×1

javascript ×1

json ×1

python ×1

python-3.x ×1

sockets ×1

tcp ×1