使用套接字传输文件 [英] file transfer using socket

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

问题描述

嗨....我正在使用sokets做客户端服务器编程。因为我必须从客户端向服务器发送大型(200 MB)数据库文件...当我发送文件时,我可以一次发送整个文件。但我无法在系统缺乏足够的缓冲空间的时候收到整个文件。所以我必须一次收到10MB ...在收到所有数据之后我将字节写为文件。我的概率是目标数据库大小大于源大小,它也是无法识别的格式。如何解决这个问题... thanx提前

hi ...., am doing client server prog using sokets. in that i have to send large(200 MB) database file from client to server ... when i send a file i could send entire file at a time. but i could't receive entire file at a time becoz of system lacked sufficient buffer space . so i have to receive 10MB at a time... after recived all data am writing bytes as a file. my prob is the destination db size is greater than source size also it's in unrecognised format. how to solve this prob... thanx in advance

推荐答案

听起来这可能是你在套接字编程方面的第一次尝试。我建议你先尝试做一些小得多的东西。使用套接字最困难的部分是了解每个Socket.Recieve()中要接收多少数据以及这是否正确。

我使用一个协议,为每个发送前缀一个整数告诉客户端需要多少字节。然后,客户端循环读取套接字并收集数据,直到它获取指定的确切字节数。然后它将使用事件将这些字节传递回应用程序。
It sounds like this may be your first venture in socket programming. I suggest you try making some thing much smaller first. The hardest part of working with sockets is understand how much data you are going to recieve in each Socket.Recieve() and whether this is correct.

I use a protocol that prefixes every send with an integer that tells the client how many bytes to expect. The client then loops through reading the socket and gather data until it pick up the exact number of bytes specified. Then it will pass those bytes back up to the application using an event.


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

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