473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

grabbing file size

i'm working on two client and server programs that send and recieve files
using sockets. i saw a c++ example using csockets, and thought i could use
the basic idea of what the code was doing to form my own c program.

i have an idea of how to send binary files via sockets, but the problem is
that to use send() i need to know the size (in bytes) of the file i want to
send.

any ideas on how to accomplish this?

--
Jesse Engle
Nov 14 '05 #1
6 1473

"Jesse Engle" <je****@elementalsn.com> wrote in message
news:_z******************@newssvr33.news.prodigy.c om...
i'm working on two client and server programs that send and recieve files
using sockets. i saw a c++ example using csockets, and thought i could use
the basic idea of what the code was doing to form my own c program.

i have an idea of how to send binary files via sockets, but the problem is
that to use send() i need to know the size (in bytes) of the file i want to send.

any ideas on how to accomplish this?

--
Jesse Engle


hi,
lets not just put it as sending files thru sockets , rather as sending
data thru sockets . split your file and therefore send your data in fixed
size buffers of say size 1024 bytes or (choose). thus you send 1024 and
receive (thereby block) on 1024 bytes. Do this inside a loop while there
still is a packet of size 1024 to send. the last send will comprise less
than 1024. immediately after that, you could close the socket using
shutdown(socket,how) and closesocket(socket). shutdown ensures that your
receive function receives the data last send (man shutdown).

kutty
Nov 14 '05 #2
Kutty Banerjee <ku****@wpi.edu> scribbled the following:
"Jesse Engle" <je****@elementalsn.com> wrote in message
news:_z******************@newssvr33.news.prodigy.c om...
i'm working on two client and server programs that send and recieve files
using sockets. i saw a c++ example using csockets, and thought i could use
the basic idea of what the code was doing to form my own c program.

i have an idea of how to send binary files via sockets, but the problem is
that to use send() i need to know the size (in bytes) of the file i want to
send.

any ideas on how to accomplish this?

hi,
lets not just put it as sending files thru sockets , rather as sending
data thru sockets . split your file and therefore send your data in fixed
size buffers of say size 1024 bytes or (choose). thus you send 1024 and
receive (thereby block) on 1024 bytes. Do this inside a loop while there
still is a packet of size 1024 to send. the last send will comprise less
than 1024. immediately after that, you could close the socket using
shutdown(socket,how) and closesocket(socket). shutdown ensures that your
receive function receives the data last send (man shutdown).


Please discuss POSIX-speficic solutions on comp.unix.programmer or
another POSIX newsgroup, thanks. None of the functions shutdown or
closesocket are ISO standard C.
Oh, and there is no such word as "thru".

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"This is a personnel commuter."
- Train driver in Scientific American
Nov 14 '05 #3

"Jesse Engle" <je****@elementalsn.com> wrote in message
news:_z******************@newssvr33.news.prodigy.c om...
i'm working on two client and server programs that send and recieve files
using sockets. i saw a c++ example using csockets, and thought i could use
the basic idea of what the code was doing to form my own c program.

i have an idea of how to send binary files via sockets, but the problem is
that to use send() i need to know the size (in bytes) of the file i want to send.

any ideas on how to accomplish this?


I would not send the file in completion at once, instead break the message
up. Note, sockets are off topic here. But here is a general way of finding
the size of a file, however it is not fully portable IIRC.

// open file and get size
int lFileSize;
FILE *lfp;
if ( (lfp=fopen(mFileName, "rb")) == NULL)
{
// error opening
return;
}
fseek(lfp, 0, SEEK_END);
lFileSize = ftell(lfp); // cant use int if more than 2GB
fseek(lfp, 0, SEEK_SET); // back to start of file
once you then come to send the file, you can do something like

#define BUFF_SIZE 1024

char lBuf[BUFF_SIZE];
int lBuffDataLength;
int lSent=0;

while(lSent < lFileSize)
{
// set the number of bytes valid in the buffer
lBuffDataLength = BUFF_SIZE;
if (lFileSize - lSent < BUFF_SIZE)
{
// if there is not enough data left to fill buffer
// then set the length of data left to buffer
lBuffDataLength = lFileSize-lSent;
}

// read a chunk of the file
fread(lBuf, lBuffDataLength, 1, lfp);

send();// this part is implementation-specific
}

<OT>
Note if you are using windows sockets, send() will send UP TO the length you
specify. To guarantee sending you will need to implement your own send()
function wrapper.
</OT>

HTH
Allan
Nov 14 '05 #4
Joona I Palaste wrote:
.... snip ...
Oh, and there is no such word as "thru".


Unfortunately there is. There was an American spelling reform
movement about a century ago, which recommended the use of thru,
tho, and others. These didn't really take.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #5
CBFalconer <cb********@yahoo.com> scribbled the following:
Joona I Palaste wrote:
... snip ...

Oh, and there is no such word as "thru".
Unfortunately there is. There was an American spelling reform
movement about a century ago, which recommended the use of thru,
tho, and others. These didn't really take.


Aw, crap. To my eyes "thru" looks just as like w4r3z d00dsp33k as "u"
or "plz" (oh, please!) does. It's amazing how some people can write an
accurate technical response spelling difficult technical words of over
5 syllables correctly, but still write "thanks" as "thx" and "please"
as "plz".
English spelling is unusually difficult anyway. Those spelling reforms
should have had real effect, such as that which ended with "...wud
finali hav kum tru".

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"O pointy birds, O pointy-pointy. Anoint my head, anointy-nointy."
- Dr. Michael Hfuhruhurr
Nov 14 '05 #6
CBFalconer <cb********@yahoo.com> writes:
Joona I Palaste wrote:

... snip ...

Oh, and there is no such word as "thru".


Unfortunately there is. There was an American spelling reform
movement about a century ago, which recommended the use of thru,
tho, and others. These didn't really take.


Well, I'm glad that this suggestion: <http://www.i18nguy.com/twain.html>
didn't catch on... ;)

Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ARGENTINA | last post by:
How do I copy using a php or cgi script a remote xml rss feed into my server? I.E the rss feed: http://www.lanacion.com.ar/herramientas/rss/index.asp?origen=2 Due to restrictions in flash...
3
by: Kris | last post by:
Dear all, I know this question has been discussed in another topic but I feel that I lack a little bit of knowledge to grasp what was said there. My problem is as follows : As a trainer in a...
4
by: InvisibleMan | last post by:
Hi, Thanks for any help in advance... I'm wondering if anyone knows how or has the resource for graabing a users email address without them knowing? Before I hear all the 'Its not ethical'...
3
by: Dizzzz | last post by:
I am creating a front end that will access a SQL database and I want to create a DROP DOWN control that will display the databases and tables available from a SQL2000 server. Much like the one in...
0
by: .Net Sports | last post by:
I've been looking everywhere, but i can't locate any functions, or articles on the net or my resources, on how to open a file using vb.net, and then grabbing certain parts of the file, and putting...
4
by: Matthew Wilson | last post by:
I wrote a function that I suspect may already exist as a python builtin, but I can't find it: def chunkify(s, chunksize): "Yield sequence s in chunks of size chunksize." for i in range(0,...
5
by: joe_doufu | last post by:
Hi, old web developer, new to Ajax and XML here. I'm developing an application that grabs an XML file from a (PHP) web service. In fact, it's going to be an online game. When the user clicks a...
1
roswara
by: roswara | last post by:
Dear all, Currently, I am working on a project to make a web-based application using ASP 2.0 and C#. This application will ask user to input for an excel file which has graphs in it. Then the...
0
by: tesis | last post by:
Hi all gurus. This' drivin' me nut: I've already posted this in dotnetframework.setup, having overlooked NG name. Excuse me. I installed Sony EyeToy in my Pc, and grabbing some code on-line,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.