【发布时间】:2021-01-30 09:34:16
【问题描述】:
当我尝试将带引号的字符串从客户端发送到服务器时,它可以工作。但是,当我尝试将存储用户输入的变量发送到服务器时,它没有。有人知道为什么吗?
server_file
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind( ("0.0.0.0", 1234) )
buff, addr = s.recvfrom(100)
print buff, addr
client_file
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
nume_user = input()
# s.sendto( nume_user, ("127.0.0.1", 1234) ) # this does not work
s.sendto("john", ("127.0.0.1", 1234) ) # this works
buff, addr = s.recvfrom(100)
print buff
这是我得到的错误(Ubuntu 18.04 LTS)
Traceback (most recent call last:
File "c4-1.py", line 5, in <module>
nume_user = input()
File "<string>", line 1, in <module>
NameError: name 'ionut' is not defined
【问题讨论】:
标签: server udp client ubuntu-18.04