<?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[Ist diese Methode okay?]]></title><description><![CDATA[<p>Hallo,</p>
<p>mögt ihr euch das mal bitte anschauen und mir sagen ob ich da irgendwas grob falsch mache? Ich bin vorallem im Bezug auf die Größe des Buffers und das \0 terminieren unsicher.</p>
<pre><code class="language-cpp">int someClass::someMethod(int sock){

	int ms = 1;

	// Buffer.    
	char checkBuffer[CHECKBUFSIZE];

	// Will hold the length of the reply.  
	int len;

	// The message to send to the server.  
	const char* message = &quot;EHLO example.org\n\r\n\r&quot;;

	// Send the message.  
	send(sock,message,strlen(message),0);

	Timer t;

	t.startTimer();

	// Read the answer and keep the length of the reply.  
	len = read(sock,checkBuffer,CHECKBUFSIZE-1);

	ms = t.stopTimer();

	// Quit message to close the connection.  
	const char* quitMessage = &quot;QUIT&quot;;

	// Send the quit message.  
	send(sock,quitMessage,strlen(quitMessage),0);

	// Terminate the string if the reply was not too long.  
	if(len &lt; CHECKBUFSIZE){
		checkBuffer[len+1] = '\0';
	}else{
		return 0;
	}

	// Make it easier for us to substr().  
	stringstream reply;
	reply &lt;&lt; checkBuffer;

	// If the first three chars are &quot;220&quot;, there is a SMTP server running.
	if(reply.str().substr(0,3) == &quot;220&quot;)
		return ms;

	return 0;
}
</code></pre>
<p>Dankeschön!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/221207/ist-diese-methode-okay</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 08:12:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/221207.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 26 Aug 2008 12:21:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ist diese Methode okay? on Tue, 26 Aug 2008 12:21:36 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>mögt ihr euch das mal bitte anschauen und mir sagen ob ich da irgendwas grob falsch mache? Ich bin vorallem im Bezug auf die Größe des Buffers und das \0 terminieren unsicher.</p>
<pre><code class="language-cpp">int someClass::someMethod(int sock){

	int ms = 1;

	// Buffer.    
	char checkBuffer[CHECKBUFSIZE];

	// Will hold the length of the reply.  
	int len;

	// The message to send to the server.  
	const char* message = &quot;EHLO example.org\n\r\n\r&quot;;

	// Send the message.  
	send(sock,message,strlen(message),0);

	Timer t;

	t.startTimer();

	// Read the answer and keep the length of the reply.  
	len = read(sock,checkBuffer,CHECKBUFSIZE-1);

	ms = t.stopTimer();

	// Quit message to close the connection.  
	const char* quitMessage = &quot;QUIT&quot;;

	// Send the quit message.  
	send(sock,quitMessage,strlen(quitMessage),0);

	// Terminate the string if the reply was not too long.  
	if(len &lt; CHECKBUFSIZE){
		checkBuffer[len+1] = '\0';
	}else{
		return 0;
	}

	// Make it easier for us to substr().  
	stringstream reply;
	reply &lt;&lt; checkBuffer;

	// If the first three chars are &quot;220&quot;, there is a SMTP server running.
	if(reply.str().substr(0,3) == &quot;220&quot;)
		return ms;

	return 0;
}
</code></pre>
<p>Dankeschön!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1571659</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1571659</guid><dc:creator><![CDATA[stanmc]]></dc:creator><pubDate>Tue, 26 Aug 2008 12:21:36 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Methode okay? on Tue, 26 Aug 2008 12:54:17 GMT]]></title><description><![CDATA[<p>Beim überfliegen einen &quot;1 daneben fehler&quot; gefunden</p>
<pre><code class="language-cpp">checkBuffer[len+1] = '\0';
</code></pre>
<p>Das +1 muss weg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1571691</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1571691</guid><dc:creator><![CDATA[templäd]]></dc:creator><pubDate>Tue, 26 Aug 2008 12:54:17 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Methode okay? on Tue, 26 Aug 2008 12:55:28 GMT]]></title><description><![CDATA[<p>Okay, Denkfehler. checkBuffer fängt bei 0 an... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> Dankeschön!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1571692</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1571692</guid><dc:creator><![CDATA[stanmc]]></dc:creator><pubDate>Tue, 26 Aug 2008 12:55:28 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Methode okay? on Tue, 26 Aug 2008 13:18:04 GMT]]></title><description><![CDATA[<p>Vom überprüfen von Rückgabe-Werten hältst du nicht viel, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1571703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1571703</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Tue, 26 Aug 2008 13:18:04 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Methode okay? on Tue, 26 Aug 2008 13:23:39 GMT]]></title><description><![CDATA[<p>Badestrand schrieb:</p>
<blockquote>
<p>Vom überprüfen von Rückgabe-Werten hältst du nicht viel, oder?</p>
</blockquote>
<p>Danke, welche genau meinst du? len?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1571708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1571708</guid><dc:creator><![CDATA[stanmc]]></dc:creator><pubDate>Tue, 26 Aug 2008 13:23:39 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Methode okay? on Tue, 26 Aug 2008 13:25:01 GMT]]></title><description><![CDATA[<p>stanmc schrieb:</p>
<blockquote>
<p>Badestrand schrieb:</p>
<blockquote>
<p>Vom überprüfen von Rückgabe-Werten hältst du nicht viel, oder?</p>
</blockquote>
<p>Danke, welche genau meinst du? len?</p>
</blockquote>
<p>Den von send und den von recv. Letzterer landet zwar in len, wird aber nicht auf Fehler überprüft. Der von send wird sogar ganz ignoriert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1571709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1571709</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 26 Aug 2008 13:25:01 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Methode okay? on Tue, 26 Aug 2008 13:45:02 GMT]]></title><description><![CDATA[<p>Das stimmt! Dank dir. Dann schau ich mir mal die Rückgabewerte an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1571733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1571733</guid><dc:creator><![CDATA[stanmc]]></dc:creator><pubDate>Tue, 26 Aug 2008 13:45:02 GMT</pubDate></item><item><title><![CDATA[Reply to Ist diese Methode okay? on Tue, 26 Aug 2008 15:45:19 GMT]]></title><description><![CDATA[<p>Und du solltest dir die Doku zu recv nochmal durchlesen. recv empfängt nicht &quot;die ganze Antwort&quot; sondern zwischen 1 und N bytes (oder 0 im Fehlerfall).<br />
D.h. du brauchst einen Loop in dem du recv so oft aufrufst bis du alle Daten empfangen hast die du brauchst.</p>
<p>EDIT: N ist die Puffergrösse die du mitgibst, also in deinem Fall CHECKBUFSIZE-1, und statt recv verwendest du read, macht aber AFAIK keinen Unterschied. /EDIT</p>
<p>Bei SMTP solltest du eine Schleife basteln die immer nur 1 Byte pro Durchgang abholt und abbricht wenn der &quot;Terminator&quot; (\r\n\r\n oder \n\r\n\r wenn ich mich richtig erinnere) empfangen wurde, da du die Länge der Antwort nicht im Voraus kennst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1571803</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1571803</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 26 Aug 2008 15:45:19 GMT</pubDate></item></channel></rss>