为什么这种语法错误?

时间:2019-05-05 22:42:16

标签: python

我正在编写一个名为 make_pos 的函数,由于某种原因,Python表示其语法不正确。

我尝试弄乱设置并更改名称,但没有任何效果。

下面是我的代码段;

git

但是会引发以下错误:

import socket
from _thread import *
import sys

server = "10.0.0.96"
port = 5555

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    s.bind((server, port))

except socket.error as e:
    str(e)

s.listen(2)
print("Waiting for a connection, Server Started")

def read_pos(str):
    str = str.split(",")
    return int(str[0], int(str[1]))

def make_pos(tup):
    return str(tup[0]) + "," + str(tup[1])

pos = [(0,0),(100,100)]
def threaded_client(conn, player):
    conn.send(str.encode(make_pos(pos[player])))
    reply = ""
    conn.send(str.encode("Connected"))
    while True:
        try:
            data = read_pos(conn.recv(2048).decode())
            pos[player] = data

            reply = data.decode("utf-8")
            if not data:
                print("Disconnected")
                break
            else:
                if player == 1:
                    reply = pos[0]
                else:
                    reply = pos[1]

                print("Recieved: ", data)
                print("Sending : ", reply)

            conn.sendall(str.encode(make_pos(reply)))
        except:
            break

    print("Lost Connection")
    conn.close()

currentPlayer = 0
while True:
    conn, addr = s.accept()
    print("Connected to:", addr)

    start_new_thread(threaded_client, (conn, currentPlayer))
    currentPlayer += 1

我在做什么错,我该如何解决?

0 个答案:

没有答案