<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem mit CAsyncSocket]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich bekomme bei der Methode bind(...,...) der MFC-Klasse CAysncSocket immer den Rückgabewert 0 und laut Hilfe steht 0 für einen Fehler. Nun hab ich mit der Methode GetLastError() die Fehlermeldung feststellen können, es ist WSAINVAL. Laut Hilfe liegt es wohl daran das er schon 'verbunden' ist, nur kann das nicht sein.</p>
<pre><code class="language-cpp">//in der stdafx.h
#include &lt;afxsock.h&gt; 

//in der InitInstance() der App-Klasse
if(!AfxSocketInit(NULL))
      AfxMessageBox(&quot;Failed to Initialize Sockets&quot;,MB_OK| MB_ICONSTOP);

//in der Dlg-Klasse
public:
    CAysncSocket  m_ASocket;

//folgende Methode ruf ich nach keinem button-klick auf
bool CCSocketTestDlg::erstelle_server(void)
{
     if(!m_ASocket.Create(m_uiPort,SOCK_DGRAM) )  //soll UDP nicht TCP
     {
	return false;
     }
     else
     {
	int z;
	struct sockaddr_in addr; 
	memset(&amp;addr, 0, sizeof(addr));  //addr nullen
         addr.sin_family = AF_INET; 
         addr.sin_port = htons(m_uiPort); 
         addr.sin_addr.S_un.S_addr = INADDR_ANY; 
	if(! m_ASocket.Bind((const sockaddr*)&amp;addr, sizeof(addr)) ) 
	{
	    z=m_ASocket.GetLastError();
			if(z == WSANOTINITIALISED )
				z=0;
			if(z == WSAENETDOWN )
				z=0;
			if(z == WSAEADDRINUSE )
				z=0;
			if(z == WSAEFAULT )
				z=0;
			if(z == WSAEINPROGRESS )
				z=0;
			if(z == WSAEAFNOSUPPORT )
				z=0;
			if(z == WSAEINVAL )  // &lt;- der fehler tritt auf
				z=0;  
			if(z == WSAENOBUFS  )
				z=0;
			if(z == WSAENOTSOCK  )
				z=0;

			return false;//fehler
		}
		return true;
	}
	//-
	return false;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/56780/problem-mit-casyncsocket</link><generator>RSS for Node</generator><lastBuildDate>Tue, 02 Jun 2026 09:33:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/56780.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Nov 2003 21:48:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit CAsyncSocket on Fri, 28 Nov 2003 21:48:41 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>ich bekomme bei der Methode bind(...,...) der MFC-Klasse CAysncSocket immer den Rückgabewert 0 und laut Hilfe steht 0 für einen Fehler. Nun hab ich mit der Methode GetLastError() die Fehlermeldung feststellen können, es ist WSAINVAL. Laut Hilfe liegt es wohl daran das er schon 'verbunden' ist, nur kann das nicht sein.</p>
<pre><code class="language-cpp">//in der stdafx.h
#include &lt;afxsock.h&gt; 

//in der InitInstance() der App-Klasse
if(!AfxSocketInit(NULL))
      AfxMessageBox(&quot;Failed to Initialize Sockets&quot;,MB_OK| MB_ICONSTOP);

//in der Dlg-Klasse
public:
    CAysncSocket  m_ASocket;

//folgende Methode ruf ich nach keinem button-klick auf
bool CCSocketTestDlg::erstelle_server(void)
{
     if(!m_ASocket.Create(m_uiPort,SOCK_DGRAM) )  //soll UDP nicht TCP
     {
	return false;
     }
     else
     {
	int z;
	struct sockaddr_in addr; 
	memset(&amp;addr, 0, sizeof(addr));  //addr nullen
         addr.sin_family = AF_INET; 
         addr.sin_port = htons(m_uiPort); 
         addr.sin_addr.S_un.S_addr = INADDR_ANY; 
	if(! m_ASocket.Bind((const sockaddr*)&amp;addr, sizeof(addr)) ) 
	{
	    z=m_ASocket.GetLastError();
			if(z == WSANOTINITIALISED )
				z=0;
			if(z == WSAENETDOWN )
				z=0;
			if(z == WSAEADDRINUSE )
				z=0;
			if(z == WSAEFAULT )
				z=0;
			if(z == WSAEINPROGRESS )
				z=0;
			if(z == WSAEAFNOSUPPORT )
				z=0;
			if(z == WSAEINVAL )  // &lt;- der fehler tritt auf
				z=0;  
			if(z == WSAENOBUFS  )
				z=0;
			if(z == WSAENOTSOCK  )
				z=0;

			return false;//fehler
		}
		return true;
	}
	//-
	return false;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/404181</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/404181</guid><dc:creator><![CDATA[RobRoy]]></dc:creator><pubDate>Fri, 28 Nov 2003 21:48:41 GMT</pubDate></item></channel></rss>