Re: strange Winsock Error by gawain
gawain
Tue Aug 05 01:42:06 CDT 2003
The first thing to start the IrDA I do is the following:
wVersion = MAKEWORD(1, 1); // Support up to Winsock 2.2
if (WSAStartup(wVersion, &wsaData)!=0)
{
wsprintf (szError, TEXT("No usable Winsock dll found."));
MessageBox (NULL, szError, TEXT("Error"), MB_OK);
return FALSE;
}
"Amit" <amitranjan@visualsoft-tech.com> schrieb im Newsbeitrag
news:#rtBywoWDHA.1580@tk2msftngp13.phx.gbl...
> Are you intializing WSADATA structure using WSASTARTUP before calling
other
> windows socket functions??
>
> Regards
> Amit
> "gawain" <gawain_knight@yahoo.com> wrote in message
> news:3f2d4bff$1@news.swissonline.ch...
> > here it comes (hole code based on the example from msdn), receive is a
> > global DWORD variable.
> >
> > if ((ClientSock = accept (ServerSock, 0, 0)) == INVALID_SOCKET)
> > {
> > wsprintf (szError, TEXT("Accepting connection with client failed.")
> > TEXT(" Error: %d"), WSAGetLastError ());
> > MessageBox (NULL, szError, TEXT("Error"), MB_OK);
> > closesocket (ServerSock);
> > return FALSE;
> > }
> >
> > // Stop listening for connections from clients.
> > closesocket (ServerSock);
> >
> > //Start a thread for handling the incoming data
> > HANDLE rt = CreateThread(NULL, NULL, receiveMessage, NULL, NULL,
> > &receive);
> >
> > WORD WINAPI receiveMessage(LPVOID lpv)
> > { while (TRUE)
> > {
> > // Receive data from the client.
> > iReturn = recv (socket, szServerA, sizeof (szServerA), 0);
> >
> > // Check if there is any data received. If there is, display it.
> > if (iReturn == SOCKET_ERROR)
> > {
> > wsprintf (szError, TEXT("No data is received, recv failed.")
> > TEXT(" Error: %d"), WSAGetLastError ());
> > MessageBox (NULL, szError, TEXT("Server"), MB_OK);
> > }
> > else if (iReturn == 0)
> > {
> > MessageBox (NULL, TEXT("Finished receiving data"), TEXT("Server"),
> > MB_OK);
> > closesocket(ClientSock);
> > ExitThread(receive);
> > }
> > else
> > {
> > // Convert the ASCII string to a Unicode string.
> > for (index = 0; index <= sizeof (szServerA); index++)
> > {
> > szServerW[index] = szServerA[index];
> > }
> >
> > /*Display the string received from the client*/
> > }
> > }
> > }
> > "Amit" <amitranjan@visualsoft-tech.com> schrieb im Newsbeitrag
> > news:e8gcYYaWDHA.572@TK2MSFTNGP11.phx.gbl...
> > > Can you show us some code?...
> > >
> > > Regards
> > > Amit
> > > "gawain" <gawain_knight@yahoo.com> wrote in message
> > > news:3f2ccf3e$1@news.swissonline.ch...
> > > > I have written a program that uses the Winsock library. But there is
> > some
> > > > strange behaviour. The server implementation has two Sockets a
> > > ServerSocket
> > > > and a ClientSocket.
> > > > For receiving messages there is a own thread, which loops forerver
> > > > (while(TRUE)) and in loop there is a recv(ClientSock,....)
statement,
> > > which
> > > > causes always an Winsock 10038 Error (use of a non-socket as
socket).
> > But
> > > > when I add the variable SOCKET sock, which is never used in my
> program,
> > > > everything works fine.
> > > >
> > > > Any idea why this?
> > > >
> > > >
> > >
> > >
> >
> >
>
>