(Python)当我尝试运行它时说无效语法

时间:2020-04-30 01:00:17

标签: python

我正在尝试构建一个聊天应用程序。有一个服务器和客户端脚本。当我运行服务器脚本时,它会带回一个错误,提示“无效语法”。错误在字端口的P上。我试过将Word从Port更改为port,但是那也不起作用。代码如下。有解决方案吗?谢谢

pair    |    times_co_participate |  co_events
1, 2    |           2             |     A, E
1, 3    |           1             |     A
1, 4    |           3             |     B, D, E
2, 3    |           2             |     A, C
2, 4    |           1             |     E
3, 4    |           0             |     null

2 个答案:

答案 0 :(得分:0)

我相信您在h_name= input(Str("Enter the hostname of the server")之后遗漏了一个

答案 1 :(得分:0)

存在以下较小的编码错误(主要是拼写错误)。 请注意,该评论带有#

import socket
import sys
import time

x=socket.socket()
h_name= input(str("Enter the hostname of the server"))  # Missing closing brackets, Str -> str
Port = 8080
x.connect((h_name,Port))  # port -> Port
print("Connected to chat server")
while True:
   incoming_message=x.recv(1024)  # s. -> x.
   incoming_messagge=incoming_message.decode()  # Extra white space and missing '_'
   print(" Server :", incoming_message)  # Missing '_' 
   message=input(str(">>"))
   message=message.encode()  # Message -> message
   x.send(message)  # s. -> x.
   print(" message has been sent...")