<?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[wiedermal boost:asio...]]></title><description><![CDATA[<p>Hi Leute,<br />
nachdem ich etwas mit Netzwerkfunktionalität programmieren möchte, dachte ich mir, dass ich mir einfach mal boost::asio ansehe;</p>
<p>gesagt,getan. Allerdings würde ich hier nichts posten wenn alles funktionieren würde -.-</p>
<p>Ich habe eine Klasse TCPServer die den Server darstellt, die aus 2 Haupt-funktionen besteht (TCPsender und TCPreceiver) die später in eigene Threads ausgelagert werden sollen.</p>
<p>TCPconn.cpp</p>
<pre><code class="language-cpp">TCPServer::TCPServer(short port):
	socket(io_service),
	acceptor(io_service, tcp::endpoint(tcp::v4(), port))
{

}
TCPServer::~TCPServer()
{

}
void TCPServer::TCPsetRecvBuffer(boost::array&lt;char, 128&gt; *buf, int len, boost::mutex *lock)
{
	p_recvBuf = buf;
	recvBufLen = len;
	p_recvLock = lock;
}

void TCPServer::TCPsetLog(vector&lt;string&gt; *log, boost::mutex *lock)
{
	p_log = log;
	p_logLock = lock;
}

void TCPServer::TCPsetSendBuffer(boost::array&lt;char, 128&gt; *buf, boost::mutex *lock)
{
	p_sendBuf = buf;
	p_sendLock = lock;	
}

void TCPServer::TCPaccept(void)
{
      	acceptor.accept(socket);
}

void TCPServer::TCPsender(void)
{
	bool exit = false;

	while(!exit){
      		boost::mutex::scoped_lock sendlock(*p_sendLock);
      		boost::system::error_code ignored_error;
		boost::asio::write(socket, boost::asio::buffer(*p_sendBuf),
		boost::asio::transfer_all(), ignored_error);

		boost::mutex::scoped_lock stoplock(stopLock);
		exit = shutdown;	
	}
}

void TCPServer::TCPreceiver(void)
{
	bool exit = false;

	while(!exit){

      		boost::mutex::scoped_lock recvlock(*p_recvLock);
      		boost::system::error_code ignored_error;
		socket.read_some(boost::asio::buffer(*p_recvBuf), ignored_error);

		boost::mutex::scoped_lock stoplock(stopLock);
		exit = shutdown;	
	}
}
</code></pre>
<p>TCPconn.hpp</p>
<pre><code class="language-cpp">using boost::asio::ip::tcp;
using namespace std;
#ifndef TCPSERVER
#define TCPSERVER
class TCPServer
{
	public:
		TCPServer(short port);			
		~TCPServer();
		//void TCPsetPort(short p);
		void TCPsetRecvBuffer(boost::array&lt;char, 128&gt; *buf, int len, boost::mutex *lock);
		void TCPsetSendBuffer(boost::array&lt;char, 128&gt; *buf, boost::mutex *lock);
		void TCPsetLog(vector&lt;string&gt; *log, boost::mutex *lock);
		void TCPaccept(void);
		void TCPreceiver(void);  //1st thread
		void TCPsender(void);    //2nd thread
		void stop(void);

	private:
		/*
		   guarantees clean thread shutdown
		*/
		bool shutdown;
		boost::mutex stopLock;
		/*
		   buffers and locks for received- and to be sent content
		*/
		boost::array&lt;char, 128&gt; *p_recvBuf,*p_sendBuf;
		int recvBufLen;
		boost::mutex *p_recvLock;
		boost::mutex *p_sendLock;
		/*
		   buffer and lock for event-logging
		*/
		vector&lt;string&gt; *p_log;
		boost::mutex *p_logLock;
		/*
		   TCP-socket
		*/
		boost::asio::io_service io_service;
		//short port;

		tcp::acceptor acceptor;
		tcp::socket socket;
};
#endif
</code></pre>
<p>und die main.cpp</p>
<pre><code class="language-cpp">#include &quot;TCPconn.hpp&quot;

int main(void)
{

	boost::array&lt;char, 128&gt;  sendBuf;
	boost::array&lt;char, 128&gt;  recvBuf;

	boost::mutex sendLock;
	boost::mutex recvLock;

	TCPServer Server((short)13);
	//Server.TCPsetPort(13);
	Server.TCPsetRecvBuffer(&amp;recvBuf,1024,&amp;recvLock);
	Server.TCPsetSendBuffer(&amp;sendBuf,&amp;sendLock);
	Server.TCPaccept();
	while(1){
		asm volatile(&quot;&quot;);  //nur zum sichergehen das nicht wegoptimiert wird
	};

}
</code></pre>
<p>und das wichtigste, die Fehlermeldung:</p>
<pre><code>./main 
terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::system::system_error&gt; &gt;'
  what():  Permission denied
Aborted
</code></pre>
<p>Ich hoffe es hat jemand Zeit sich das anzusehen und mir zu helfen.</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/260746/wiedermal-boost-asio</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 22:43:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/260746.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Feb 2010 23:12:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to wiedermal boost:asio... on Mon, 08 Feb 2010 23:12:47 GMT]]></title><description><![CDATA[<p>Hi Leute,<br />
nachdem ich etwas mit Netzwerkfunktionalität programmieren möchte, dachte ich mir, dass ich mir einfach mal boost::asio ansehe;</p>
<p>gesagt,getan. Allerdings würde ich hier nichts posten wenn alles funktionieren würde -.-</p>
<p>Ich habe eine Klasse TCPServer die den Server darstellt, die aus 2 Haupt-funktionen besteht (TCPsender und TCPreceiver) die später in eigene Threads ausgelagert werden sollen.</p>
<p>TCPconn.cpp</p>
<pre><code class="language-cpp">TCPServer::TCPServer(short port):
	socket(io_service),
	acceptor(io_service, tcp::endpoint(tcp::v4(), port))
{

}
TCPServer::~TCPServer()
{

}
void TCPServer::TCPsetRecvBuffer(boost::array&lt;char, 128&gt; *buf, int len, boost::mutex *lock)
{
	p_recvBuf = buf;
	recvBufLen = len;
	p_recvLock = lock;
}

void TCPServer::TCPsetLog(vector&lt;string&gt; *log, boost::mutex *lock)
{
	p_log = log;
	p_logLock = lock;
}

void TCPServer::TCPsetSendBuffer(boost::array&lt;char, 128&gt; *buf, boost::mutex *lock)
{
	p_sendBuf = buf;
	p_sendLock = lock;	
}

void TCPServer::TCPaccept(void)
{
      	acceptor.accept(socket);
}

void TCPServer::TCPsender(void)
{
	bool exit = false;

	while(!exit){
      		boost::mutex::scoped_lock sendlock(*p_sendLock);
      		boost::system::error_code ignored_error;
		boost::asio::write(socket, boost::asio::buffer(*p_sendBuf),
		boost::asio::transfer_all(), ignored_error);

		boost::mutex::scoped_lock stoplock(stopLock);
		exit = shutdown;	
	}
}

void TCPServer::TCPreceiver(void)
{
	bool exit = false;

	while(!exit){

      		boost::mutex::scoped_lock recvlock(*p_recvLock);
      		boost::system::error_code ignored_error;
		socket.read_some(boost::asio::buffer(*p_recvBuf), ignored_error);

		boost::mutex::scoped_lock stoplock(stopLock);
		exit = shutdown;	
	}
}
</code></pre>
<p>TCPconn.hpp</p>
<pre><code class="language-cpp">using boost::asio::ip::tcp;
using namespace std;
#ifndef TCPSERVER
#define TCPSERVER
class TCPServer
{
	public:
		TCPServer(short port);			
		~TCPServer();
		//void TCPsetPort(short p);
		void TCPsetRecvBuffer(boost::array&lt;char, 128&gt; *buf, int len, boost::mutex *lock);
		void TCPsetSendBuffer(boost::array&lt;char, 128&gt; *buf, boost::mutex *lock);
		void TCPsetLog(vector&lt;string&gt; *log, boost::mutex *lock);
		void TCPaccept(void);
		void TCPreceiver(void);  //1st thread
		void TCPsender(void);    //2nd thread
		void stop(void);

	private:
		/*
		   guarantees clean thread shutdown
		*/
		bool shutdown;
		boost::mutex stopLock;
		/*
		   buffers and locks for received- and to be sent content
		*/
		boost::array&lt;char, 128&gt; *p_recvBuf,*p_sendBuf;
		int recvBufLen;
		boost::mutex *p_recvLock;
		boost::mutex *p_sendLock;
		/*
		   buffer and lock for event-logging
		*/
		vector&lt;string&gt; *p_log;
		boost::mutex *p_logLock;
		/*
		   TCP-socket
		*/
		boost::asio::io_service io_service;
		//short port;

		tcp::acceptor acceptor;
		tcp::socket socket;
};
#endif
</code></pre>
<p>und die main.cpp</p>
<pre><code class="language-cpp">#include &quot;TCPconn.hpp&quot;

int main(void)
{

	boost::array&lt;char, 128&gt;  sendBuf;
	boost::array&lt;char, 128&gt;  recvBuf;

	boost::mutex sendLock;
	boost::mutex recvLock;

	TCPServer Server((short)13);
	//Server.TCPsetPort(13);
	Server.TCPsetRecvBuffer(&amp;recvBuf,1024,&amp;recvLock);
	Server.TCPsetSendBuffer(&amp;sendBuf,&amp;sendLock);
	Server.TCPaccept();
	while(1){
		asm volatile(&quot;&quot;);  //nur zum sichergehen das nicht wegoptimiert wird
	};

}
</code></pre>
<p>und das wichtigste, die Fehlermeldung:</p>
<pre><code>./main 
terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::system::system_error&gt; &gt;'
  what():  Permission denied
Aborted
</code></pre>
<p>Ich hoffe es hat jemand Zeit sich das anzusehen und mir zu helfen.</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1852786</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1852786</guid><dc:creator><![CDATA[Vezweifelter]]></dc:creator><pubDate>Mon, 08 Feb 2010 23:12:47 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 05:52:01 GMT]]></title><description><![CDATA[<p>Sieht nach einer regulären Exception aus. Fang sie mal mit:</p>
<pre><code class="language-cpp">catch(boost::system::system_error &amp;) 
{ 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1852831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1852831</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Tue, 09 Feb 2010 05:52:01 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 12:09:49 GMT]]></title><description><![CDATA[<p>Die Exception ist:</p>
<pre><code>Permission denied
</code></pre>
<p>Aber leider steht nicht wo...</p>
<p>MFG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853031</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853031</guid><dc:creator><![CDATA[Verzweifelter]]></dc:creator><pubDate>Tue, 09 Feb 2010 12:09:49 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 12:21:15 GMT]]></title><description><![CDATA[<p>Jetzt hab ich das ganze als root ausgeführ und es kommt schon mal keine Exception mehr.<br />
Doch würde ich gerne wissen warum ich es nur als root und nicht als normaler User ausführen kann. Ich benutze Ubuntu;</p>
<p>MFG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853039</guid><dc:creator><![CDATA[Verzweifelter]]></dc:creator><pubDate>Tue, 09 Feb 2010 12:21:15 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 14:19:27 GMT]]></title><description><![CDATA[<p>So, nachdem ich jetzt noch schnell einen Client geschrieben habe, gibt der mir als Antwort:</p>
<pre><code>Connection refused
</code></pre>
<p>Was mach ich falsch???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853150</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853150</guid><dc:creator><![CDATA[Vezweifelter]]></dc:creator><pubDate>Tue, 09 Feb 2010 14:19:27 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 14:20:44 GMT]]></title><description><![CDATA[<p>Wie, wo, wann, in welchem Client? Mehr Infos bitte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853151</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Tue, 09 Feb 2010 14:20:44 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 14:34:25 GMT]]></title><description><![CDATA[<p>ok hier kommt der Client:</p>
<pre><code class="language-cpp">class TCPClient
{
	public:
		TCPClient(string ip,short port);
		~TCPClient();
		void setRecvBuffer(boost::array&lt;char, 1024&gt; *buf, boost::mutex *lock);
		void setSendBuffer(boost::array&lt;char, 1024&gt; *buf, boost::mutex *lock);
		void setLog(vector&lt;string&gt; *log, boost::mutex *lock);
		bool connect(void);
		void receiver(void);
		void sender(void);
	private:
		/*
		   guarantees clean thread shutdown
		*/
		bool shutdown;
		boost::mutex stopLock;
		/*
		   buffers and locks for received- and to be sent content
		*/
		boost::array&lt;char, 1024&gt; *p_recvBuf;
		boost::array&lt;char, 1024&gt; *p_sendBuf;

		boost::mutex *p_recvLock;
		boost::mutex *p_sendLock;
		/*
		   buffer and lock for event-logging
		*/
		vector&lt;string&gt; *p_log;
		boost::mutex *p_logLock;
		/*
		   TCP-socket
		*/
		short port;
		boost::asio::ip::address ipaddress;

		boost::asio::io_service io_service;

		tcp::socket socket;
};
</code></pre>
<p>main:</p>
<pre><code class="language-cpp">int main(void)
{
	try
	{
		boost::array&lt;char, 1024&gt;  sendBuf;
		boost::array&lt;char, 1024&gt;  recvBuf;

		boost::mutex sendLock;
		boost::mutex recvLock;

		TCPClient Client(&quot;127.0.0.1&quot;,13);
		//Server.TCPsetPort(13);
		Client.setRecvBuffer(&amp;recvBuf,&amp;recvLock); // Buffer must be of length 1024
		Client.setSendBuffer(&amp;sendBuf,&amp;sendLock); // Buffer must be of length 1024
		Client.connect();
		while(1){
			asm volatile(&quot;&quot;);
		};
	}
	catch(boost::system::system_error &amp;e) 
	{ 
		printf(&quot;%s\n&quot;,e.what());
	}

}
</code></pre>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853161</guid><dc:creator><![CDATA[Vezweifelter]]></dc:creator><pubDate>Tue, 09 Feb 2010 14:34:25 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 14:35:31 GMT]]></title><description><![CDATA[<p>sry hab die .cpp vergessen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code class="language-cpp">TCPClient::TCPClient(string ip, short p):
	socket(io_service)
{
	ipaddress.from_string(ip.c_str());
	port = p;
}

TCPClient::~TCPClient()
{

}

void TCPClient::setRecvBuffer(boost::array&lt;char, 1024&gt; *buf, boost::mutex *lock)
{
	p_recvBuf = buf;
	p_recvLock = lock;
}

void TCPClient::setSendBuffer(boost::array&lt;char, 1024&gt; *buf, boost::mutex *lock)
{
	p_sendBuf = buf;
	p_sendLock = lock;
}

void TCPClient::setLog(vector&lt;string&gt; *log, boost::mutex *lock)
{
	p_log = log;
	p_logLock = lock;
}

bool TCPClient::connect(void)
{
	boost::system::error_code error;
	boost::asio::ip::tcp::endpoint endpt;
	endpt.address(ipaddress);
	socket.connect(endpt,error);
	if (error)
      		throw boost::system::system_error(error);
}

void TCPClient::receiver(void)
{
	bool exit = false;
	while(!exit)
	{
		boost::mutex::scoped_lock recvlock(*p_recvLock);
      		boost::system::error_code ignored_error;
		socket.read_some(boost::asio::buffer(*p_recvBuf), ignored_error);

		boost::mutex::scoped_lock stoplock(stopLock);
		exit = shutdown;
	}
}

void TCPClient::sender(void)
{
	bool exit = false;

	while(!exit){
      		boost::mutex::scoped_lock sendlock(*p_sendLock);
      		boost::system::error_code ignored_error;
		boost::asio::write(socket, boost::asio::buffer(*p_sendBuf),
		boost::asio::transfer_all(), ignored_error);

		boost::mutex::scoped_lock stoplock(stopLock);
		exit = shutdown;	
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1853162</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853162</guid><dc:creator><![CDATA[Verzweifelter]]></dc:creator><pubDate>Tue, 09 Feb 2010 14:35:31 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 15:46:02 GMT]]></title><description><![CDATA[<p>Auf POSIX-Systemen können die ports unter 1024 nur vom &quot;root&quot; benutzt werden um einen Server darauf zum lauschen anzulegen.</p>
<p>BR</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853202</guid><dc:creator><![CDATA[evilissimo]]></dc:creator><pubDate>Tue, 09 Feb 2010 15:46:02 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 15:50:54 GMT]]></title><description><![CDATA[<p>Ich hab es jetzt auf Port 4000 gelegt und kann den Server zwar jetzt ohne root-Rechte ausführen,<br />
allerdings bekomme ich vom Client immer noch ein &quot;Connection refused&quot; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853207</guid><dc:creator><![CDATA[Verzweifelter]]></dc:creator><pubDate>Tue, 09 Feb 2010 15:50:54 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 15:59:07 GMT]]></title><description><![CDATA[<p>Außerdem ist Port 13 für den DayTime-Dienst reserviert: <a href="http://de.wikipedia.org/wiki/Daytime" rel="nofollow">http://de.wikipedia.org/wiki/Daytime</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853215</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Tue, 09 Feb 2010 15:59:07 GMT</pubDate></item><item><title><![CDATA[Reply to wiedermal boost:asio... on Tue, 09 Feb 2010 17:00:59 GMT]]></title><description><![CDATA[<p>So Leute, ich denke ich habe das Problem gefunden:</p>
<p>Ich habe beim Verbinden keinen Port angegeben.</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1853247</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1853247</guid><dc:creator><![CDATA[Verzweifelter]]></dc:creator><pubDate>Tue, 09 Feb 2010 17:00:59 GMT</pubDate></item></channel></rss>