文件传输应用 [英] File Transfer application

查看:111
本文介绍了文件传输应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好每一个我想问一个有关使用套接字文件传输问题。连接后,我打开文件在客户端,并开始读取数据和数据发送到服务器我做的客户端服务器的code。服务器打开一个文件读取插口,数据并写入到文件。它工作正常,但现在我想,我的文件名应该是双方都相同。为了实现这一点,我有从客户端发送的文件名到服务器,但问题是,服务器读取文件名,并且也读取一些数据并进行了错误的文件名

Hello every one I want to ask a question about file transfer using sockets. I have made a code of client server after connection I open the file at client side and start reading the data and send that data to server. Server opens a file read that data from socket and write it to file. It's working fine but now I want that my file name should be same at both sides. To achieve this I have send the file name from client side to server but the problem is that the server reads the file name and also read some data and make the wrong file name.

例如:

file name: myfile.txt
data in the file is : hello how are you.


server create the file name myfile.txthellow how  

我怎样才能避免这种情况,因为我不知道这是什么文件名在服务器大小大小
谢谢

How can I avoid this as I dont know that what is the size of file name at server size Thanks

推荐答案

有几种选择:


  1. 的文件名(如 NUL \\ n )后发送特殊字符。

  2. preFIX其字节长度的文件名。

  1. Send a special character after the file name (e.g. NUL or \n).
  2. Prefix the file name with its length in bytes.

在接收端,这两个文件的名称和该数据将到达作为字节单个流。但是,服务器现在有足够的信息来找出其中的文件名结束,数据开始。

On the receiving end, both the file name and the data will arrive as a single stream of bytes. However, the server now has enough information to figure out where the file name ends and the data begins.

这篇关于文件传输应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆