C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 07-04-2009, 09:49 AM   #1
Registered User
 
Join Date: Dec 2007
Location: France
Posts: 396
recv() second arg

I dont know if it makes any sense but its kinda strange what i found.

From the client i send send(server, size, 8, 0); with the second arg: char* size.

On the server i recv(client, size, 8, 0); with the second arg: char size[8].

If i change the type to char* size on the server too, it stops working.

Its not that important but maybe someone had an idea why is that.
__________________
Using Code::Blocks,MingW with Windows.
Ducky is offline   Reply With Quote
Old 07-04-2009, 11:23 AM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
> If i change the type to char* size on the server too, it stops working.
You become responsible for making sure it points to allocated memory.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 07-04-2009, 12:57 PM   #3
Registered User
 
Join Date: Dec 2007
Location: France
Posts: 396
Thank you Salem!

So i guess it means i shouldnt use it if its not allocated.

By allocated i guess you mean, dynamically like that:

Code:
char* size = new char[8];
Unfortunately i have to use char* size because with char size[8] it wont compile on that line on the client side.

Code:
                     strcpy(Cmd, "Upload");
                     send(server, Cmd, 7, 0);
                     Sleep(5);
                     send(server, RemoteP, MAX_PATH, 0);
                     ifstream r(LocalP, ios::in | ios::binary);
                     // get size of file:
                     r.seekg (0, ios::end);
                     sz = r.tellg();
                     r.seekg (0, ios::beg);
                     // error: need char* for size
                     size = itoa(sz, buff, 10);
                     send(server, size, 8, 0);

                     char* Buffer = new char [sz];
                     ZeroMemory(Buffer, sz);
                     r.read(Buffer, sz);
                     send(server, Buffer, sz, 0);
                     cout << Buffer << endl;

                     r.close();
                     delete[] Buffer;
__________________
Using Code::Blocks,MingW with Windows.

Last edited by Ducky; 07-04-2009 at 01:10 PM.
Ducky is offline   Reply With Quote
Old 07-04-2009, 02:17 PM   #4
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
Try reading the manual page for itoa then.
Quote:
Originally Posted by a man page
RETURN VALUES

The function itoa() always returns the value string. There is no error return.
Forget about size, just use buff
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 07-04-2009, 02:48 PM   #5
Registered User
 
Join Date: Dec 2007
Location: France
Posts: 396
Thanks a lot, its working!
__________________
Using Code::Blocks,MingW with Windows.
Ducky is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer to struct Paul Johnston C Programming 4 06-11-2009 03:01 AM
manipulating arg in the: function(char* arg); without returning it[C,freebsd7.1,gcc] mali2 C Programming 10 06-08-2009 02:42 PM
Question about recv carrotcake1029 Networking/Device Communication 2 02-26-2009 02:10 PM
Ranged numbers Desolation Game Programming 8 07-25-2006 10:02 PM
recv() afisher Networking/Device Communication 3 03-24-2004 05:32 PM


All times are GMT -6. The time now is 05:47 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22