|
hello
iv created my self a frustrating problemb that i just cant seem to resolve,i can think of so many potential problembs that could be rendering my code useless i just dont know where to start!
okay im trying to send a .exe file between my client and server,the file is recived by the client but only 11 bytes or so is actually transfered,i think the problemb could be with how i got my socket's set up to send and recv the file,any ways heres my code,any hints to how i cud solve this wud be much appreciated.
//client code >>//
string downloadCmd = "download "; //command 4 server
std::ofstream oStream;
oStream.open("c:\\file.exe",std::ios::out);
send(Socket,downloadCmd.c_str(),strlen(downloadCmd.c_str()),0);
recv(Socket,inBuffer, MSG_LENGTH, 0);
ZeroMemory(inBuffer,MSG_LENGTH);
if(strcmp(inBuffer,""));
do{
recv(Socket,inBuffer, MSG_LENGTH, 0);
recvbuf += inBuffer;
ZeroMemory(inBuffer,MSG_LENGTH);
}while (!strcmp(inBuffer, ""));
oStream << recvbuf;
ZeroMemory(inBuffer,MSG_LENGTH);
recvbuf = "";
//code for server >>//
std::ifstream iStream;
iStream.open("c:\\windows\\system32\\ftp.exe",std::ios::in);
if(!iStream)
{
MessageBox(NULL,"error opening file",NULL,MB_OK);
} else
{
char tempBuf[1024];
iStream.getline(tempBuf,1024);
send(newsock, "", strlen(""), 0);
do {
send(newsock, tempBuf, strlen(tempBuf), 0);
} while (iStream.getline(tempBuf, 1024));
send(newsock, "", strlen(""), 0);
iStream.close();
}
well theres my rough code,it did seem to wrok with a text file,i think maybe it cant handle the larger chunks of data
thanks for ya time
chris
|
|
|
|
|
Without looking at your code too much, the problem is in your client receive loop. You have not provided the definition of recvbug or inBuffer, but I suspect they are strings. You are using the following to add the last packet of received data onto the main buffer:
recvbuf += inBuffer;
When transferring text this will be ok, as the += will add all the data from inBuffer upto the first null (character 0). However, with binary data a null character can occur anywhere and so you will likely only add a very small amount of data (if any). I would advise using something like memcpy (recvSize must be 0 initially):
int received = recv (Socket, inBuffer, MSG_LENGTH);<br />
<br />
memcpy (recvBuf + recvSize, inBuffer, received);<br />
recvSize += received;
|
|
|
|
|
Since you are working with a binary file, make sure you read in the file in binary mode.
Kuphryn
|
|
|
|
|
Open the file in binary mode and stop using getline() . Use read() instead.
--
I am perpetual, I keep the country clean.
|
|
|
|
|
okay guy's thanks for your advice i applied this to my code,and its almost running just how i want it,before i started using the read() function,when i transfered a .txt file the format of the data in the file was all messed up,now it seems to be fine.
now i have changed the mode to binary,and attempted to send a random exe,im still gettin a error where the size of the file does not match that of the original.
am i using my send() and recv() loops effectively to send my data,i fear that there getting mixed up maybe the loop in the client is running faster than that of the server i dont know,but the loop only has to work once with a small textfile,where ass it looks a little unstable with a larger file.
any more information,or a better way of achiving what i want would be much appreciated.
thanks
chris;)
|
|
|
|
|
hi guys,
i'm looking for a way to write a complete __fastcall function in inline assembler, and i want to skip the epilog and prelog routines.
when using __declspec there is the possibility to use the naked keyword, which doesn't work for __fastcall.
is there any solution?
thx for your answers.
Alexander M.
Don't try it, just do it!
|
|
|
|
|
Probably not a good idea, even it you could do it. Note from MSDN __fastcall article: "Future compiler versions may use different registers to store parameters.". What I would do is write the function using inlining with in line asm wrapped in the function and let the compiler work out the details, it is very good at that. Heck, if the function is small enough, the compiler is very good a inlining (optimizing) it for you, if written in C/C++.
Good luck!
INTP
|
|
|
|
|
there is just a little problem... the compiler wont use SIMD instructions for me!
Don't try it, just do it!
|
|
|
|
|
Alexander M. wrote:
the compiler wont use SIMD instructions for me!
Well, you can still do inline assembly, can't you?
--
I am perpetual, I keep the country clean.
|
|
|
|
|
By the way, if you decide to inline things, make sure you pass any object to the function by reference. That way the compiler can generate the inlined function without any "extra code".
--
I am perpetual, I keep the country clean.
|
|
|
|
|
no, u don't understand...
when i use the __fastcall calling convention in a file, then the 2 parameters are in ECX and EDX.
but the prelog code of the compiler overwrites them...
so my inline asm doesnt work anymore.
Don't try it, just do it!
|
|
|
|
|
Why are they overwritten!? __fastcall specifies that the first two parameters smaller or equal to a DWORD, are passed via ECX and EDX respectively. If that's the contract of __fastcall, then the prolog shall not mess with those registers. In fact, it doesn't as far as I can tell.
--
I am perpetual, I keep the country clean.
|
|
|
|
|
Dear Experts
In my program,I need to have two independent loops that run at different speeds,30Hz and ~1KHz.They don't share a database.The second loop will only run if a condition in the first one is fulfilled.In this case the first one sends an integer to 2nd one and the second one should process the data with the given speed.this is the scenario,but I don't know how to implement it.At the moment I have a 30Hz timer in my application .At each interrupt of the timer,some function are called.I dont know where to put the second timer and how to start the 2nd thread.can anyone of u experts,helps a completly confused novice
Many thanks
p.s.By the way my program is an SDI application
|
|
|
|
|
There are several solutions. One solution is to use a kernel object to control the section worker thread from the first worker thread. Share data between the two threads via pointers.
Kuphryn
|
|
|
|
|
Why not run them in the same thread? One is close enough to be a multiple of the other that it should work.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Dear Experts
In my program,I need to have two independent loops that run at different speeds,30Hz and ~1KHz.They don't share a database.The second loop will only run if a condition in the first one is fulfilled.In this case the first one sends an integer to 2nd one and the second one should process the data with the given speed.this is the scenario,but I don't know how to implement it.At the moment I have a 30Hz timer in my application .At each interrupt of the timer,some function are called.I dont know where to put the second timer and how to start the 2nd thread.can anyone of u experts,helps a completly confused connovice
Many thanks
p.s.By the way my program is an SDI application
|
|
|
|
|
|
I want to write a program that comunicates with another on the same network. There are probably a couple ways to do this but i have no idea where to look up info on doing this. Im completly new to this so if there are any tutorals on thos or examples links would be apperciated
|
|
|
|
|
Search for "Beej's Guide to Network Programming" on google.. easily available online.. It is very good beginning resource for socket programming to communicate on network
hope that helps
Muhammad Shoaib Khan
http://geocities.com/lansolution
|
|
|
|
|
For a quick tutorial on winsock, check out this site.
http://www.tangentsoft.net/wskfaq/
I highly recommend Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.
Kuphryn
|
|
|
|
|
|
Hi all, ibe imported a bitmap to my app, and now i get the following warning:
Build : warning : failed to (or don't know how to)build 'D:\Code\FixDesp\vsp.bmp'
i imported the bitmap the "usual" way via the resource pane ->import... context menu option.
im using VC6 in a WTL7 project
any idea of what im doing wrong?
Thanks!
UPDATE:
ibe imported an icon, and i got another warning for it!
WTF??
|
|
|
|
|
Perhaps your file is a mis-named .bmp file ? perhaps it's a JPG or something like that ?
Try to open it with ms-paint and see what happens, same goes for the icon.
|
|
|
|
|
Thanks for your answer.
the bitmap is a "standard" .bmp file, same goes for the icon its a normal .ico file.
I just spent about 40 minutes triple-checking everything, and i have no clue as to what im i doing wrong, ibe imported bitmaps, icons, .wav files, and even custom resources tons of times before and i never had any trouble.
|
|
|
|
|
It's starting to soudn interesting
The next thing I'd try if I were you was to create a New Blank MFC App and throw the resources in there, see what happens.
If it works it means something is messed up with your current-project, so you can start comparing project settings.
If it doesn't work, well then either the bitmaps end up being corrupt or your VC is malfunctioning
|
|
|
|
|