I/O 流、套接字编程、互操作性
我目前正在用java制作一个客户端-服务器文件传输程序,我的问题是,
是否有最好或合适的I/O流来通过不同程序的套接字传输文件?
我对什么感到困惑使用...
到目前为止,我只是使用 bufferedoutputstream/bufferedinputstream 对,即使它有效,似乎所有概念都缺少一些东西...
我真正想知道的是 我将使用什么流通过套接字传输任何文件如果我要通过字节数组传输它们,
并且
如果其他不是用java编写的程序(比如c++)必须能够接收并保存发送的文件... (序列化涉及这个吗?)
谢谢。 :)
I am currently making a client-server file transfer program in java and my question is,
is there a best or an appropriate I/O streams to transfer files via sockets of different programs?
i am confused about what to used....
so far, i'm just using the bufferedoutputstream/bufferedinputstream pair and even though it works, it seems that there is something missing with all the concepts in mind...
what i really want to know is what stream will i use to transfer any files via socket if i am going to transfer them by byte array
and
if other program not written in java (let say c++) must be able to receive and save the sent file... (does serialization involve this?)
thanks. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
流/缓冲区类的组合不会产生任何影响。您需要选择一种在所有平台上都易于以相同方式读取/写入的格式。例如,对于不同的处理器架构来说,写入表示数字的二进制数据更难(尽管并非不可能)读取。
为什么不使用 HTTP 作为协议?它主要发送纯文本行,使用空行作为分隔符。这样做的优点之一是您可以使用大量现有工具来调试/分析您的系统,例如curl、Fiddler、任何网络浏览器等。数千个平台已经存在客户端(和服务器框架)。
The combination of stream/buffer classes will make no difference. You need to choose a format that is easy to read/write in the same way on all platforms. For example, writing binary data representing numbers is harder (though not impossible) for different processor architectures to read.
Why not use HTTP as your protocol? It mostly sends lines of plain text, using blank lines as delimiters. Among the advantages of this is that you can use a wealth of existing tools to debug/analyse your system, e.g. curl, Fiddler, any web browser, etc. Clients (and server frameworks) already exist for thousands of platforms.