<?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[recv() abbrechen wenn nichts zurück kommt]]></title><description><![CDATA[<p>moin</p>
<p>hab da nen kleines problem: ich möchte einen industrie-drucker abfragen bzw ihm sagen das er ein bestimmtes label laden soll.<br />
hierbei kann es aber vorkommen, das entweder ein rückgabewert kommt oder aber auch eben nicht, das gar nichts zurück kommt.</p>
<p>nun hab ich als empfangsmethode diese gewählt:</p>
<pre><code>int ReceiveFromClient(int soc)
{
	CAVSCApp* pApp = (CAVSCApp*)AfxGetApp();
    char buffer[1024];
    for (int i = 0; i &lt; sizeof(buffer) - 1; i++){
		buffer[i]=NULL;
	}
    pApp-&gt;message = &quot;&quot;;
    int bytes;
	CString tmp=&quot;&quot;;
    do {
        bytes = recv(soc, buffer, sizeof(buffer) - 1, 0);
        // Alles ok
        if (bytes &gt; 0) {   
            // Datenmüll löschen
            buffer[bytes] = '\0';
            for (int i = 0; i &lt; bytes; i++){
				tmp.Format(&quot;%02x &quot;, (unsigned char)buffer[i]);
				pApp-&gt;message += tmp;
			}
			pApp-&gt;message.TrimRight();
			//AfxMessageBox(&quot;'&quot;+pApp-&gt;message+&quot;'&quot;);
            return 0;
        }
    }
    while (bytes &gt; 0);

    if (bytes == -1) {
       return 1;
    } else if (bytes == 0){
        return 2;
    }else{
        return 0;
    }
}
</code></pre>
<p>hierbei hab ich aber das problem das eben wenn nichts zurück kommt sich mein programm genau bei dem recive verabschiedet.</p>
<p>wie kann ich das so umprogrammieren, das ich vielleicht vorher nachgucke ob es was zum abholen gibt und wenn net dann lass ich es ansonsten führe ich diese funktion aus?</p>
<p>mfg LT</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/316387/recv-abbrechen-wenn-nichts-zurück-kommt</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Jul 2026 07:14:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/316387.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 May 2013 07:44:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to recv() abbrechen wenn nichts zurück kommt on Thu, 02 May 2013 07:44:35 GMT]]></title><description><![CDATA[<p>moin</p>
<p>hab da nen kleines problem: ich möchte einen industrie-drucker abfragen bzw ihm sagen das er ein bestimmtes label laden soll.<br />
hierbei kann es aber vorkommen, das entweder ein rückgabewert kommt oder aber auch eben nicht, das gar nichts zurück kommt.</p>
<p>nun hab ich als empfangsmethode diese gewählt:</p>
<pre><code>int ReceiveFromClient(int soc)
{
	CAVSCApp* pApp = (CAVSCApp*)AfxGetApp();
    char buffer[1024];
    for (int i = 0; i &lt; sizeof(buffer) - 1; i++){
		buffer[i]=NULL;
	}
    pApp-&gt;message = &quot;&quot;;
    int bytes;
	CString tmp=&quot;&quot;;
    do {
        bytes = recv(soc, buffer, sizeof(buffer) - 1, 0);
        // Alles ok
        if (bytes &gt; 0) {   
            // Datenmüll löschen
            buffer[bytes] = '\0';
            for (int i = 0; i &lt; bytes; i++){
				tmp.Format(&quot;%02x &quot;, (unsigned char)buffer[i]);
				pApp-&gt;message += tmp;
			}
			pApp-&gt;message.TrimRight();
			//AfxMessageBox(&quot;'&quot;+pApp-&gt;message+&quot;'&quot;);
            return 0;
        }
    }
    while (bytes &gt; 0);

    if (bytes == -1) {
       return 1;
    } else if (bytes == 0){
        return 2;
    }else{
        return 0;
    }
}
</code></pre>
<p>hierbei hab ich aber das problem das eben wenn nichts zurück kommt sich mein programm genau bei dem recive verabschiedet.</p>
<p>wie kann ich das so umprogrammieren, das ich vielleicht vorher nachgucke ob es was zum abholen gibt und wenn net dann lass ich es ansonsten führe ich diese funktion aus?</p>
<p>mfg LT</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2320248</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2320248</guid><dc:creator><![CDATA[LordTerra]]></dc:creator><pubDate>Thu, 02 May 2013 07:44:35 GMT</pubDate></item><item><title><![CDATA[Reply to recv() abbrechen wenn nichts zurück kommt on Thu, 02 May 2013 08:09:29 GMT]]></title><description><![CDATA[<p>Deine Socket-API sollte eine select - Funktion zur Verfügung stellen. Für Windows-OSe siehe:<br />
<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms740141%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2320256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2320256</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Thu, 02 May 2013 08:09:29 GMT</pubDate></item></channel></rss>