![]() |
| | #1 |
| Registered User Join Date: Dec 2007 Location: France
Posts: 395
| recv() second arg 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 online now | |
| | #2 |
| and the hat of vanishing 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 | |
| | #3 |
| Registered User Join Date: Dec 2007 Location: France
Posts: 395
| 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]; 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 online now | |
| | #4 | |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| Try reading the manual page for itoa then. Quote:
__________________ 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 | |
| | #5 |
| Registered User Join Date: Dec 2007 Location: France
Posts: 395
| Thanks a lot, its working!
__________________ Using Code::Blocks,MingW with Windows. |
| Ducky is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |