|
Alex Cutovoi wrote: So, do I need to put the SendData and RecieveData functions in a thread right? Can you give me a sample?
You don't need to but you can. If there's so much data being sent and received that it degrades
the UI performance then it's probably a good idea. If you only transfer small amounts not very
often then you could leave your send/recv calls on the UI thread.
Alex Cutovoi wrote: This is the hard part, how can I check in app there unsent bytes?
The return value of the socket send() and recv() APIs are slightly different.
Both return SOCKET_ERROR if an error occurs, which means no bytes were transferred. For an async
socket if the error was WSAEWOULDBLOCK then it means data could't be transferred right away (no
bytes were received or send buffer is full) so you'll need to try again.
For send(), a successful return value is the number of bytes sent, which may not be all the bytes
you requested to be sent.
For recv(), a successful return value is the number of bytes received, which may not be all the
bytes you requested to be received. If recv() returns 0 that means the connection has been
closed.
So, a generic example of handling these return values could be something like this:
int nBytesToRecv = ...;
BYTE *pRecvBytes = ...;
while (nBytesToRecv > 0)
{
int nBytesReceived = ::recv(sock, (char*)pRecvBytes, nBytesToRecv, 0);
if (nBytesReceived == SOCKET_ERROR)
{
int nSockError = ::WSAGetLastError();
if (nSockError != WSAEWOULDBLOCK)
{
break;
}
}
else
{
nBytesToRecv -= nBytesReceived;
if (nBytesToRecv > 0)
pRecvBytes += nBytesReceived;
}
}
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Very thanks mike, I have a direction now.
But one more thing, I want to send a struct between the apps. To fill the nBytesToRecv var, in my case, just I call the sizeof() func to fill it?
Thanks for the help in this topic.
|
|
|
|
|
Alex Cutovoi wrote: To fill the nBytesToRecv var, in my case, just I call the sizeof() func to fill it?
Generally yes. As long as the two ends use the same byte ordering for multi-byte numeric types
(int, etc.). Both ends should be compiled using the same structure padding as well.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Thanks mark, now I get some more knowledge to code my app
|
|
|
|
|
Hi all,
I am making one win32 application using VC++.NET 2003. I want to make screen capturing for specific area on screen as a part of my application. I know how to capture whole screen or a window using CreateCompatibleBitmap(); but I don’t know how can I capture specific rectangle area from it. Can I get some help please?
Thanks in Advance,
Priyank
|
|
|
|
|
See this[^] article.
/ravi
|
|
|
|
|
Thanks but that capturing tool is not capturing sepcific area. I have Left, Right, Top and Bottom coordinates of screen. I want to capture only that area.
Priyank
|
|
|
|
|
priyank_ldce wrote: that capturing tool is not capturing sepcific area.
Interesting. The opening sentence "This article demonstrates the methods of capturing different portions of the screen." and the reference to this method left me thinking otherwise:
HBITMAP CopyScreenToBitmap(LPRECT lpRect); /ravi
|
|
|
|
|
How about capure the entire screen and then use a bitblt copy operation to extract the part you want? Seems reasonable enough to me unless you don't think the entire screen will fit into memory or some other simple constraint such as that
|
|
|
|
|
or how about just capturing the rect you want the same way you capture en entire screen except
create the destination bitmap the size of the rect and use the correct offsets/size in a BitBlt()
call.
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
I am working with tool bar in dialog based application. How to show tool tip help for the tool bar items? Thanks in advance.
|
|
|
|
|
|
See this[^] article.
/ravi
|
|
|
|
|
I am developing a flight simulator application that has a MDI interface to entry settings and read some status information. However, I am little lost where i should place the main state machine/loop that controls all of the motion based incoming UDP sockets messasges. Right now, I envision creating a class that starts it's own thread calling running that will recieve and process all the motions movement. Is this a good way to setup a systems. The UDP socket can recieve up to 30 motion commands per second.
//Peusodo Code
<br />
<br />
void service_motion::Runnning( void ) <br />
{<br />
UDP_Socket.GetPacket( &cmdpkt );<br />
<br />
switch( state )<br />
{<br />
<br />
case BOARDING:<br />
if( inputs == OK ) <br />
state = DOCKED_DOWN;<br />
break;<br />
<br />
case DOCKED_DOWN:<br />
if( cmdpkt.opcode == START_GAME )<br />
state = RUNNING;<br />
break;<br />
<br />
<br />
case PAUSED:<br />
break;<br />
<br />
case RUNNING:<br />
if( cmdpkt.opcode == PAUSE )<br />
state = PAUSED;<br />
<br />
if( cmdpkt.opcode == STOP)<br />
{<br />
stop_motion();<br />
state = PAUSED;<br />
}<br />
<br />
break;<br />
<br />
case EMERGENCY:<br />
<br />
break;<br />
<br />
case RECOVERY:<br />
break;<br />
<br />
<br />
<br />
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan wrote: switch( state )
That's not a state machine
led mike
|
|
|
|
|
led mike wrote: That's not a state machine
A switch statement is a perfectly fine way to implement a FSM. I'm curious why you feel otherwise?
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: A switch statement is a perfectly fine way to implement a FSM.
Whatever
led mike
|
|
|
|
|
Can this be accomplished using Events or messages? Does it make more sense to read the commands from UDP socket outside the Running Thread and send messages and/or events to FSM?
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan, I have no idea what your project parameters are:
A flight simulator
A UDP Socket
30 UDP commands per second
controls all the motion
EMERGENCY - Disables network commands
What commands? From what? Why a Socket? What Motion? What is "EMERGENCY"? What does "Disables network commands" mean?
What is the desired "result" of all this?
led mike
|
|
|
|
|
Dude, what are you talking about?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
|
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hi all
Could anyone please show me a good link which gives an in depth study of C++, i mean how the storage occurs, how an object is kept in memory, how all the things are done under ground.
Regards
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|
|
|
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|