|
If a printf("aprintf OK"); is added after calling aprintf,
the message "aprintf OK" can be shown.
then goes to return TRUE;
But printf("returned") if added in the lower function, it does not show "returned".
So, I think something causes the exception for exiting the upper function.
Please advise.
|
|
|
|
|
I'm not sure what the server is sending you, but you send this many bytes
(int)strlen(message),
to the server (you're not sending the NULL terminator at the end of the message).
On the first receive from the server you assume the string is NULL terminated
if(astr.Set(szBuf))
Try either sending "strlen(message) + 1" bytes or using "if(astr.Set(szBuf,nRet))" instead of
"if(astr.Set(szBuf))".
Mark
|
|
|
|
|
Thanks Mark!
I tried to send "strlen(message) + 1" bytes to the server.
The exception appears less often, but still occurs.
The exception message is:
"DAMAGE: after Normal block (#1409) at 0x0032EF20"
I cannot use 'try' to catch it. Using debug mode fails to locate the error line...
Please help me again.
It should be very close to the solution.
Thanks!
|
|
|
|
|
Archyami wrote: I tried to send "strlen(message) + 1" bytes to the server.
The exception appears less often, but still occurs
That's fine. You need to do the same on your sends FROM the server as well otherwise this line
is going to be problematic on the client side:
if(astr.Set(szBuf))
You are still assuming that szBuf has a NULL terminator. Whether or not this is causing the
exception I don't know.
A few notes and questions...
You allocate a receive buffer CATOS_BUFFER_SIZE+1 bytes in length but only recv CATOS_BUFFER_SIZE
bytes into it. Why?
I believe you mentioned using blocking sockets in another post. If so, the Sleep() call is
useless since the second recv call will block until you receive some more bytes or the
socket closes or error occurs. It looks like you're waiting until "for sure" all the bytes have
arrived before trying the second receive. This may work for a few "packets" but is very
inefficient for a tcp socket. Instead, it works better to keep calling recv until you get the
bytes you are expecting (remember, recv() won't always give them all to you in one call). To
receive CATOS_BUFFER_SIZE bytes try something like:
szBuf=(char*)malloc(sizeof(char)*(CATOS_BUFFER_SIZE+1));
int TotalBytesReceived = 0;
while (TotalBytesReceived < CATOS_BUFFER_SIZE)
{
int CurBytesReceived = ::recv(theSocket, &szBuf[TotalBytesReceived], CATOS_BUFFER_SIZE - TotalBytesReceived, 0);
if (CurBytesReceived == 0)
{
break;
}
else if (CurBytesReceived == SOCKET_ERROR)
{
int rc = WSAGetLastError();
if (rc != WSAEWOULDBLOCK)
{
break;
}
}
else
{
TotalBytesReceived += CurBytesReceived;
}
}
if (TotalBytesReceived == CATOS_BUFFER_SIZE)
{
}
else
{
}
Make sure you send EXACTLY CATOS_BUFFER_SIZE from the server...if you don't you'll be stuck in
the loop waiting If you can't always send the right amount you could timeout or something.
Mark
EDIT: By the way, you shouldn't ever get a WSAEWOULDBLOCK error on a blocking socket.
I added the check for WSAEWOULDBLOCK as an example of using a non-blocking socket.
More EDITS: Bad grammer, spelling, attitude, etc.
-- modified at 22:32 Thursday 19th October, 2006
|
|
|
|
|
I modified the server "send" with data length +1.
The exception does not occur.
Thanks very much, Mark!
I have a few questions:
1. The message eg. equals "abc". Its length is 3.
Why should I send its length as 4?
(The server is checked to send data within the length of CATOS_BUFFER_SIZE.)
2. The recv buffer is allocated with 1 more byte for safe (may be it is a risk...)
My design is that if CATOS_BUFFER_SIZE==10 and message comes from the server as "1234567890", it can hold the message. Indeed, a terminator is at the end (here is '0'). If '\0' is padded by the server, it can still hold the message.
'\0' is padded automatically for initializing an char array.
Please advise if my analysis is wrong.
3. If the server is checked to send data within the length of CATOS_BUFFER_SIZE, is it possible that the client recv() may receive the message sereral times instead of once?
I mean: recv() holds the application (thread). 'several times' refers to 1 recv() receives a part of the message, several recv() receives all message 'packages'.
Please advise.
|
|
|
|
|
Archyami wrote: 1. The message eg. equals "abc". Its length is 3.
Why should I send its length as 4?
(The server is checked to send data within the length of CATOS_BUFFER_SIZE.)
I don't think you SHOULD send 4. I was just trying to fix your exception before. If you
have 3 bytes to send then send 3 bytes
Archyami wrote: 2. The recv buffer is allocated with 1 more byte for safe (may be it is a risk...)
My design is that if CATOS_BUFFER_SIZE==10 and message comes from the server as "1234567890", it can hold the message. Indeed, a terminator is at the end (here is '0'). If '\0' is padded by the server, it can still hold the message.
'\0' is padded automatically for initializing an char array.
Please advise if my analysis is wrong.
If you want to send the '\0' WITH the string of characters "1234567890" then you need to
send 11 bytes. It is up to YOU to send and receive the correct amount of bytes.
Archyami wrote: 3. If the server is checked to send data within the length of CATOS_BUFFER_SIZE, is it possible that the client recv() may receive the message sereral times instead of once?
I mean: recv() holds the application (thread). 'several times' refers to 1 recv() receives a part of the message, several recv() receives all message 'packages'.
I'll try to explain this again...TCP knows NOTHING about "packages" or "packets" - it only
knows a STREAM of bytes. You can send 1000 bytes and on the other end you may receive
all 1000 bytes in one call to recv(), you may receive 10 bytes in one call to recv() and
990 bytes in the next call to recv(), etc.. It's all about BYTES and it's up to you keep
calling recv() until you get the number of bytes you are expecting.
If you always want to recv the same number of bytes you send then you need to use a
message/datagram based protocol like UDP.
I suggest reading this Windows Sockets 2[^].
Mark
|
|
|
|
|
Hi all,
How to add a work sheet in excel without using ODBC drivers?
|
|
|
|
|
|
when i am trying to add new ATL object but after clicking that option it will give error
"Error Invoking ATL Object Wizard Component"
And when i have tried this to other machine then also i got error like
"sorry !an error occurred while generating the object
Can anybody help me here why this error are coming how to solve it
|
|
|
|
|
|
Does this help?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Dear all
how to add a class which don't attach .cpp and .h files?i can't understand their project.thank u. urgent!!!!!!!
Li Zhiyuan
18/10/2006
|
|
|
|
|
Usually a class is declared in .h file and defined in a .cpp file, but it is possible to do this in a single file, if thats what you mean. The only other way I know of to add a class (without using source files) is to add a dll to the project. But even here it is difficult to export a class without the relevent header file.
|
|
|
|
|
Can you be more specific a class without cpp & h
|
|
|
|
|
li zhiyuan wrote: how to add a class which don't attach .cpp and .h files?
You can't. A class has to be in one or the other, but usually split between the two.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
To preserve thread integrity, you might want to respond to Li instead.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
oh dear, I though I did.
Fixed and deleted original message
Darka [ Xanya]
"I am not a slave to a god that doesn't exist."
|
|
|
|
|
We need more info.
If you send us the details of the project your university has given you, then we may be able to help but without further information, we cannot.
i.e. Exactly what was the question being asked ?
Darka [ Xanya]
"I am not a slave to a god that doesn't exist."
|
|
|
|
|
Hi All,
I have a CListCtrl in report view with images. Whenever an Item gets highlighted, I lose the image.
Can anyone tell me how to keep the image from dissapearing?
P1p3r
|
|
|
|
|
How are you setting the item's image?
I_IMAGECALLBACK or an index into your image list?
|
|
|
|
|
Hi Mark,
Thanks for the info.
I finally figured it out. I had set the color wrong when I created the image.
Thanks again.
P1p3r
|
|
|
|
|
I'd make sure that the mask in the imagelist is correct. The most common way is to have a unique color in the bitmap that becomes transparent when drawn on the screen.
|
|
|
|
|
Hi Michael,
Thanks for the heads up.
I guess that's what I needed.
|
|
|
|
|
I come from the managed world and have no idea about unmanaged dlls!
So, I have a few unmanaged dlls I want to interop with using pinvoke, etc...
However, these dlls are undocumented so I have no idea, what parameters the methods take, or return.. I don't even know what methods are in the dll at all!
How can I peek into the unmanaged dll to see a signature of the methods? I've been messing around with dependency walker and pe explorer and those enable me to see what methods are inside the dll but neither of them provide information regarding the parameters or return types.
Am I just using them wrong? How can I get this information?
/\ |_ E X E GG
|
|
|
|
|
eggie5 wrote: However, these dlls are undocumented so I have no idea, what parameters the methods take, or return.. I don't even know what methods are in the dll at all!
How do you know you want to interop with them then?
Mark
|
|
|
|