Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

是否可以查看客户端的所开的端口 #149

Open
Lj-dog opened this issue Aug 26, 2024 · 4 comments
Open

是否可以查看客户端的所开的端口 #149

Lj-dog opened this issue Aug 26, 2024 · 4 comments

Comments

@Lj-dog
Copy link

Lj-dog commented Aug 26, 2024

  一般连接后,服务端可以看到连接的客户端的 IP|Port 那其实客户端也能知道自己的IP|Port. 这个可以在哪里看到呢?

@Neutree
Copy link
Owner

Neutree commented Aug 26, 2024

软件没做这个,一般不会用到这个功能吧,在服务端那边可以看到没必要在客户端这边看

@Neutree
Copy link
Owner

Neutree commented Aug 26, 2024

不过一定要看的话是可以的,可以自己加上, demo 如下:

import socket

# 创建一个 socket 对象
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 连接到服务器
server_address = ('localhost', 12345)
client_socket.connect(server_address)

# 获取客户端的 IP 地址和端口号
client_ip, client_port = client_socket.getsockname()

print(f"Client IP: {client_ip}, Client Port: {client_port}")

# 关闭连接
client_socket.close()

@Lj-dog
Copy link
Author

Lj-dog commented Sep 25, 2024

软件没做这个,一般不会用到这个功能吧,在服务端那边可以看到没必要在客户端这边看

1、感觉在实际生产中还是有必要的,比如说我一个连了很多个客户端的服务端程序(能看到哪个客户端:他的IP|Port,传来的未反序列化的数据),并一直有数据传输。这时候知道Clinet的IP|Port,在Server上直接查找,会比不知道IP|Port 使用排除法查找要高效得多。
2、我看来下,这项目与传统的有ui文件,并使用Desinger编写界面的Qt工程不同。我不太懂,可以粗略介绍下开发框架,和要是要加的话 需要在哪里修改呢?
comtool

@Neutree
Copy link
Owner

Neutree commented Sep 25, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants