小编pro*_*mer的帖子

仅从套接字接收一个字节

我用python编写了一个服务器程序.

我想要一个字符串,但我只有一个角色!我怎么才能收到一个字符串?

def handleclient(connection):                                           
    while True:                             
        rec = connection.recv(200)
        if rec == "help": #when I put help in the client program, rec = 'h' and not to "help"
            connection.send("Help Menu!")


    connection.send(rec)
    connection.close()

def main():
   while True:
        connection, addr = sckobj.accept()   
        connection.send("Hello\n\r")
        connection.send("Message: ")   
        IpClient = addr[0]
        print 'Server was connected by :',IpClient


        thread.start_new(handleclient, (connection,))   
Run Code Online (Sandbox Code Playgroud)

python sockets socketserver

6
推荐指数
1
解决办法
3876
查看次数

标签 统计

python ×1

sockets ×1

socketserver ×1