|
In my code within switch case LOOP_CLIENT, I poll for events. I am getting a FD_CONNECT event but I know the clientsocket is not connected. In fact the server socket application is not even running yet. I was hoping that I would only get a FD_CONNECT event after the client socket connected with server socket, and a FD_CLOSE after a connection has been broken.
Right now, i can not garantee that which socket will be running first. So, i need some way to find the status of the client socket and possibly cancel/restart the connetion attempt.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
I should have qualified that with "a successful" FD_CONNECT.
Check for an error:
WSAEnumNetworkEvents(client_socket, g_hClientEvent, &NetworkClientEvents);
switch ( NetworkClientEvents.lNetworkEvents )
{
...
case FD_CONNECT:
if (0 != NetworkClientEvents.iErrorCode[FD_CONNECT_BIT])
printf("Connect Failed Message: \n\r");
else
printf("Client Connected Message: \n\r");
break;
...
}
Out of curiosity, why would you poll if you are using an event? It just needlessly eats CPU time.
|
|
|
|
|
Thanks Mark, that seem to work! I found in the MSDN that a FD_CONNECT error can be used to extract more information but, i am have not had success getting that information. I am guessing that FD_CONNECT_BIT is the indexing for the 10 array element of iErrorCode. Where can i find the other meanings of the array elements.
Additional error codes can be set when an application window receives a message. This error code is extracted from the lParam in the reply message using the WSAGETSELECTERROR macro. Possible error codes for each network event are listed in the following table.
Event: FD_CONNECT
Error code Meaning
WSAEAFNOSUPPORT Addresses in the specified family cannot be used with this socket.
WSAECONNREFUSED The attempt to connect was rejected.
WSAENETUNREACH The network cannot be reached from this host at this time.
WSAEFAULT The namelen parameter is invalid.
WSAEINVAL The socket is already bound to an address.
WSAEISCONN The socket is already connected.
WSAEMFILE No more file descriptors are available.
WSAENOBUFS No buffer space is available. The socket cannot be connected.
WSAENOTCONN The socket is not connected.
WSAETIMEDOUT Attempt to connect timed out without establishing a connection.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan wrote: I am guessing that FD_CONNECT_BIT is the indexing for the 10 array element of iErrorCode. Where can i find the other meanings of the array elements.
Correctemundo. In the platform SDK, Windows Sockets 2, under WSANETWORKEVENTS struct:
iErrorCode
Array that contains any associated error codes, with an array index that corresponds to the
position of event bits in lNetworkEvents. The identifiers FD_READ_BIT, FD_WRITE_BIT and others
can be used to index the iErrorCode array.
They were too lazy to list them
ScotDolan wrote: Additional error codes can be set when an application window receives a message. This error code is extracted from the lParam in the reply message using the WSAGETSELECTERROR macro.
That would be if you were using windows-based events (WSAAsyncSelect) I believe.
Since you are using WSAEventSelect, you get the error messages codes from the WSANETWORKEVENTS struct.
Mark
-- modified at 18:35 Monday 22nd January, 2007
|
|
|
|
|
In my post above I stated "Since you are using WSAEventSelect, you get the error messages from
the WSANETWORKEVENTS struct."
I forgot to mention that it only applies when WSAGetLastError() after a failed non-blocking
socket op returns WSAEWOULDBLOCK. Sometimes the error is reported immediately and you'll never
get the FD_xxx event.
Mark
|
|
|
|
|
For what i am learning, it seems like WSAAsyncSelect() with WSAGETSELECTERROR marco might be a better solution than WSAEnumNetworkEvents(client_socket, g_hClientEvent, &NetworkClientEvents);
It seems that WSAAsyncSelect() will provide me with more information and less chance of missing a event.
A FD_CLOSE event produce the below error codes, but from what I understand if want to use WSAEnumNetworkEvents( ) I will not be able to get access to the below error message without a call to WSAGetLastError() and even that might miss a error code.
WSAEAFNOSUPPORT, Addresses in the specified family cannot be used with this socket.
WSAECONNREFUSED, The attempt to connect was rejected.
WSAENETUNREACH, The network cannot be reached from this host at this time.
WSAEFAULT, The namelen parameter is invalid.
WSAEINVAL, The socket is already bound to an address.
WSAEISCONN, The socket is already connected.
WSAEMFILE, No more file descriptors are available.
WSAENOBUFS, No buffer space is available. The socket cannot be connected.
WSAENOTCONN, The socket is not connected.
WSAETIMEDOUT, Attempt to connect timed out without establishing a connection.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan wrote: For what i am learning, it seems like WSAAsyncSelect() with WSAGETSELECTERROR marco might be a better solution than WSAEnumNetworkEvents(client_socket, g_hClientEvent, &NetworkClientEvents);
It seems that WSAAsyncSelect() will provide me with more information and less chance of missing a event.
Unless you're using a buggy socket implementation, you won't miss any events using either method.
The difference is, WSAAsyncSelect uses a window to notify you. WSAEventSelect uses an event.
The window method is only really useful if you want to do asynchronous socket ops in a single
threaded app. If you have a separate thread for socket communication then an event is easier
and more efficient (the thread can wait on the event).
I'm not sure what you're getting at with the FD_CLOSE errors. I wouldn't expect any error
(or even look for one). After receiving the FD_CLOSE notification there's nothing that can
be done on the socket except reading any remaining unread/buffered receive data.
Mark
|
|
|
|
|
Also, see Mike's post below
|
|
|
|
|
Don't use a switch statement to check the network event. More than one event can be signalled at a time. The events will be OR 'd together.
Mike
|
|
|
|
|
Thanks Mike!
I didn't even think about that....I just copy/pasted from the OP's code
Mark
|
|
|
|
|
I didn't realize it was the OP's code (which was so long and unformatted that I barely even glanced at it). Sorry.
Mike
|
|
|
|
|
No problem. I always appreciate a heads up when I'm wrong
|
|
|
|
|
Hi,
I am using the Windows API to write some code that uses the end user's already installed Adobe Acrobat Reader to open up a *.PDF file. My problem is locating the file. Everytime Adobe upgrades to another version of Adobe Acrobat the pathname changes, say for example from
C:\Program Files\Adobe\Acrobat 5.0\Reader\Acrord32.exe
to
C:\Program Files\Adobe\Acrobat 7.0\Reader\Acrord32.exe
which at the moment causes the routine to fail unless I have specified the correct directory.
I am guessing there must be a much better way to do this, could anybody point me in the right direction? I would assume that you can ask the operating system what *.exe it uses to open up *.pdf and tell it to use that, but I am unsure how I code that.
Could someone point me in the right direction?
Thanks,
Joe
|
|
|
|
|
You can call ShellExecute using as argument the path of the document to open (instead of that of the executable, see MSDN documentation for details...).
hope that helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
TheDelChop wrote: I am guessing there must be a much better way to do this, could anybody point me in the right direction? I would assume that you can ask the operating system what *.exe it uses to open up *.pdf and tell it to use that, but I am unsure how I code that.
http://visualcpp.org/template_permalink.asp?id=125[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Dear All.
I need to create a Bitmap output file from statistical data without showing to screen. The image will be built in memory and then output to file. I will need to do this in VC++ SDK, not MFC. Can anyone point me in the right direction on this one? (Books / examples / links... etc) I've tried looking around and there are lots of examples of Loading bitmaps and outputting to screen but none on building and outputting from memory.
Many thanks
u6ik
|
|
|
|
|
Are you wanting to know the format of a .bmp file?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
You can create a memory device context by means of CreateCompatibleDC (see the related documentation) then use the GDI primitives to draw on it (all the example you have also applies to memory device context).
Hope that helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Do you want to create a graphic file?
|
|
|
|
|
Yes. A BMP file which can be opened using any BMP viewer.
I know how to handle files, but what to put in it, that's the problem.
Cheers
u6ik
|
|
|
|
|
Hi all. I was trying to get a better understanding of the winAPI function WaitForMultipleObjects() - I searched msdn for a answer to what it is/does etc. But i didnt fully understand what it was trying to tell.
<quote>
This function returns a value when either any one of the specified objects is in the signaled state, or the time-out interval elapses.
That was the definition for it <url=http: msdn2.microsoft.com="" fr-fr="" library="" aa450987.aspx="">here
If anyone could give me a address to where i can find a fully detailed description of the function i'd be very greatful. Or if they could take the time to exaplain. Thanx in advance!
|
|
|
|
|
What exactly is it that you don't understand? Once the function is called, it waits. Objects start life in a non-signaled state, and can later be set to a signaled state, which the function recognizes.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Does anyone has an idea why the diff = difftime(my2, my1); fragment in the following code returns always zero?
char date1[60], date2[60];
struct tm mytime, mytime2;
time_t my1, my2;
mytime.tm_isdst = -1;
mytime.tm_year = 2006;
mytime.tm_mon = 1;
mytime.tm_mday = 1;
mytime.tm_hour = 0;
mytime.tm_min = 0;
mytime.tm_sec = 0;
my1 = mktime(&mytime);
strftime(date1 ,60 , "%x", &mytime2);
mytime2.tm_isdst = -1;
mytime2.tm_year = 2006;
mytime2.tm_mon = 1;
mytime2.tm_mday = 3;
mytime2.tm_hour = 0;
mytime2.tm_min = 0;
mytime2.tm_sec = 0;
my2 = mktime(&mytime2);
strftime(date2 ,60 , "%x", &mytime2);
diff = difftime(my2, my1);
printf(date1);
printf(date2);
printf("Difference in seconds: %f\n", diff);
Regards,
Deian
|
|
|
|
|
Deian wrote: strftime(date1 ,60 , "%x", &mytime2);
Should probably be:
strftime(date1 ,60 , "%x", &mytime1);
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|