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?

Re: strange Winsock Error by Amit

Amit
Sun Aug 03 17:31:55 CDT 2003

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?
>
>



Re: strange Winsock Error by gawain

gawain
Sun Aug 03 12:54:29 CDT 2003

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?
> >
> >
>
>



Re: strange Winsock Error by Dado

Dado
Sun Aug 03 12:52:59 CDT 2003

On Sun, 3 Aug 2003 11:02:13 +0200, "gawain" <gawain_knight@yahoo.com>
wrote:

>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.

I've got kind the same error, winsock 10038.

I didnt understand why but I just moved the socked initialization few
lines above the message loop and everything worked fine.

I reckon there's some order depencency somewhere in the pocketPC
implementation, never had that problem with PC developing.

If I were lazier I could have debugged it better :P

HTH,
Dado.


Re: strange Winsock Error by Amit

Amit
Mon Aug 04 20:59:06 CDT 2003

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?
> > >
> > >
> >
> >
>
>



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?
> > > >
> > > >
> > >
> > >
> >
> >
>
>