Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.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客户端移动到c#服务器_C#_Python_Sockets_Readfile - Fatal编程技术网

试图将文件从python客户端移动到c#服务器

试图将文件从python客户端移动到c#服务器,c#,python,sockets,readfile,C#,Python,Sockets,Readfile,我试图将一个jpg映像从一台PC中的c#服务器复制到另一台PC中的python客户端。 这样做的目的只是阅读图像内容: string text = File.ReadAllText(newPath); //or byte[] text = File.ReadAllBytes(newPath); 并将文本与以下内容一起发送: Byte[] sendBytes = text networ

我试图将一个jpg映像从一台PC中的c#服务器复制到另一台PC中的python客户端。 这样做的目的只是阅读图像内容:

        string text = File.ReadAllText(newPath);
        //or
        byte[] text = File.ReadAllBytes(newPath);
并将文本与以下内容一起发送:

                Byte[] sendBytes = text
                networkStream.Write(sendBytes, 0, sendBytes.Length);
                networkStream.Flush();
python客户端接收文本并立即将其保存到jpg文件中

我知道这听起来很疯狂,但它奏效了我在另一台服务器上看到了它,想知道他们是如何做到的

我找了好几天的解决方案,但我始终只接收部分数据(如果文件是7.78MB,我只接收7.74MB)

我已经在这里检查了重复的帖子,我所发现的只是将文件从同一语言服务器传输到同一语言客户端

我尝试使用
StreamReader
BitConverter
,但仍然只能得到部分图像,而不是全部图像

保存接收到的图像的python代码为:

    rcvdD = socketPCP.recv(512000000) #I thought that the recv Size is causing to the problem
    try:
            filename = "image.jpg"
            print "NAME:",filename
            print "\n\r\n\rNEW FILE RECIEVED!\n\r\n\r"
            f=open ('D:/Files/'+filename , 'w')
            f.write(rcvdD)
    except Exception,e:
            print e

谢谢大家!

我对python不太在行,但我记得你应该不断地将每个块追加到最终缓冲区中,直到你收到一个零长度的数据或一个错误,然后将缓冲区中的内容写入磁盘。

好的,我成功地发送了图像,但我仍然无法正确地查看它,我可以看到它已损坏,我认为这与python Receive的大小有关。是的,我尝试过:while true:data=socket.recv(1)if not data:break totaldata+=data,但仍然不起作用。请阅读本文,了解python中有关recvall的良好解释。