Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与python服务器共享文件_Python_File_Server_Share - Fatal编程技术网

与python服务器共享文件

与python服务器共享文件,python,file,server,share,Python,File,Server,Share,我正在python服务器上工作。我已经创建了服务器和客户端。 服务器: 客户: 现在,我正在尝试在客户端和服务器之间共享消息,不仅仅是通过字符串的变量,还包括一些文件。 例如,我需要从客户端向服务器发送一个.jpg文件。 关于我该怎么做,你有什么想法或建议吗?非常感谢啊,你找到了方法! 我搜索时没有看到你链接的帖子! 我在下面写下你所指的帖子: import socket, threading class ClientThread(threading.Thread): def __init

我正在python服务器上工作。我已经创建了服务器和客户端。 服务器:

客户:

现在,我正在尝试在客户端和服务器之间共享消息,不仅仅是通过字符串的变量,还包括一些文件。 例如,我需要从客户端向服务器发送一个.jpg文件。
关于我该怎么做,你有什么想法或建议吗?

非常感谢啊,你找到了方法! 我搜索时没有看到你链接的帖子! 我在下面写下你所指的帖子:

import socket, threading

class ClientThread(threading.Thread):

def __init__(self,ip,port):
    threading.Thread.__init__(self)
    self.ip = ip
    self.port = port
    print "[+] New thread started for "+ip+":"+str(port)

def run(self):    
    print "Connection from : "+ip+":"+str(port)
    stop = False
    while stop == False:
        try:
             data = clientsock.recv(2048)
             print "["+ip+"] : "+data
             clientsock.send("You sent me: "+data)
        except:
             stop = True
    print "[-] Close thread for  "+ip

host = "x.x.x.x"
port = 9999

tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

tcpsock.bind((host,port))
threads = []


while True:
    tcpsock.listen(4)
    print "\nListening for incoming connections..."
    (clientsock, (ip, port)) = tcpsock.accept()
    newthread = ClientThread(ip, port)
    newthread.start()
    threads.append(newthread)

for t in threads:
    t.join()
import socket
import sys
HOST, PORT = "x.x.x.x", 9999
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
print " Connect to server !!"
msg='o'
while msg != "close":
    msg= raw_input("Ask user for something >>")
    sock.sendall(msg)
    try:
        msg1 = sock.recv(2048)
    except:
        print"server closed"
        msg1='nothing !!'
        msg='close'
    print'server reply >' +msg1
    print""
print"just press enter"
raw_input()