<?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[Struct über connected Socket senden]]></title><description><![CDATA[<p>I've a problem with sending a structure of the type pkt over my connected socket. I've not too much experience in programming C/C++. Thus, I've no clue what the problem could be. I've spent quite a lot of time in this but didn't got the problem. I'm using sendmsg() and recvmsg(). Both seems to work. But when I try to access the received data, I recognize that the results are completely wrong (probably initial values instead of received data). Can anybody tell me my mistake? Would be great!</p>
<p>CLIENT:</p>
<pre><code class="language-cpp">int main ( int argc, int argv[] )
{
	struct msghdr msg;
	struct iovec iov[1];
	struct pkt {
		int a;
		int b;
	} p ;
	p.a = 123;
	p.b = 234;

	iov[0].iov_base = &amp;p;
	iov[0].iov_len = sizeof(p);

	try
	{
		ClientSocket client_socket ( &quot;localhost&quot;, 30000 );

		std::string reply;
		std::string message;

		try
		{
			msg.msg_iov = iov ;
			msg.msg_iovlen = 1 ;
			msg.msg_name = NULL ;
			msg.msg_namelen = 0 ;
			msg.msg_control = (caddr_t) &amp;p ;
  			msg.msg_controllen = sizeof (struct pkt) ;
  			msg.msg_flags = 0 ;

			client_socket &lt;&lt; msg ;
		}
</code></pre>
<p>...</p>
<p>SERVER:</p>
<pre><code class="language-cpp">int main ( int argc, int argv[] )
{
	struct iovec iov[1]; 
	struct msghdr inmessage;
	char * buffer_rcv;

	struct pkt {
		int a;
		int b;
	} inp ;

	try
    {
		// Create the socket
		ServerSocket server ( 30000 ) ;

		while ( true )
		{
			ServerSocket new_sock ;
			server.accept ( new_sock ) ;

			try
			{
				while ( true )
				{
					buffer_rcv = (char*)memset(&amp;inmessage, 0, sizeof(inmessage));

					iov[0].iov_base = buffer_rcv; 
					iov[0].iov_len = sizeof(inmessage);

					inmessage.msg_iov = iov; 
					inmessage.msg_iovlen = 1; 
					inmessage.msg_name = NULL; 
					inmessage.msg_namelen = 0; 
					inmessage.msg_control = (caddr_t) &amp;inp; 
					inmessage.msg_controllen = sizeof (struct pkt); 
					inmessage.msg_flags = 0;

					new_sock &gt;&gt; inmessage;

					std::cout &lt;&lt; &quot;inp.a: '&quot; &lt;&lt; inp.a &lt;&lt; &quot;'&quot; &lt;&lt; endl;  // returns 134522371
					std::cout &lt;&lt; &quot;inp.b: '&quot; &lt;&lt; inp.b &lt;&lt; &quot;'&quot; &lt;&lt; endl;  // 134522371 too
</code></pre>
<p>....</p>
<p>Vielen Dank. Grüsse, Simu</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/152730/struct-über-connected-socket-senden</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 04:08:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/152730.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 09 Jul 2006 11:06:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Struct über connected Socket senden on Sun, 09 Jul 2006 11:06:20 GMT]]></title><description><![CDATA[<p>I've a problem with sending a structure of the type pkt over my connected socket. I've not too much experience in programming C/C++. Thus, I've no clue what the problem could be. I've spent quite a lot of time in this but didn't got the problem. I'm using sendmsg() and recvmsg(). Both seems to work. But when I try to access the received data, I recognize that the results are completely wrong (probably initial values instead of received data). Can anybody tell me my mistake? Would be great!</p>
<p>CLIENT:</p>
<pre><code class="language-cpp">int main ( int argc, int argv[] )
{
	struct msghdr msg;
	struct iovec iov[1];
	struct pkt {
		int a;
		int b;
	} p ;
	p.a = 123;
	p.b = 234;

	iov[0].iov_base = &amp;p;
	iov[0].iov_len = sizeof(p);

	try
	{
		ClientSocket client_socket ( &quot;localhost&quot;, 30000 );

		std::string reply;
		std::string message;

		try
		{
			msg.msg_iov = iov ;
			msg.msg_iovlen = 1 ;
			msg.msg_name = NULL ;
			msg.msg_namelen = 0 ;
			msg.msg_control = (caddr_t) &amp;p ;
  			msg.msg_controllen = sizeof (struct pkt) ;
  			msg.msg_flags = 0 ;

			client_socket &lt;&lt; msg ;
		}
</code></pre>
<p>...</p>
<p>SERVER:</p>
<pre><code class="language-cpp">int main ( int argc, int argv[] )
{
	struct iovec iov[1]; 
	struct msghdr inmessage;
	char * buffer_rcv;

	struct pkt {
		int a;
		int b;
	} inp ;

	try
    {
		// Create the socket
		ServerSocket server ( 30000 ) ;

		while ( true )
		{
			ServerSocket new_sock ;
			server.accept ( new_sock ) ;

			try
			{
				while ( true )
				{
					buffer_rcv = (char*)memset(&amp;inmessage, 0, sizeof(inmessage));

					iov[0].iov_base = buffer_rcv; 
					iov[0].iov_len = sizeof(inmessage);

					inmessage.msg_iov = iov; 
					inmessage.msg_iovlen = 1; 
					inmessage.msg_name = NULL; 
					inmessage.msg_namelen = 0; 
					inmessage.msg_control = (caddr_t) &amp;inp; 
					inmessage.msg_controllen = sizeof (struct pkt); 
					inmessage.msg_flags = 0;

					new_sock &gt;&gt; inmessage;

					std::cout &lt;&lt; &quot;inp.a: '&quot; &lt;&lt; inp.a &lt;&lt; &quot;'&quot; &lt;&lt; endl;  // returns 134522371
					std::cout &lt;&lt; &quot;inp.b: '&quot; &lt;&lt; inp.b &lt;&lt; &quot;'&quot; &lt;&lt; endl;  // 134522371 too
</code></pre>
<p>....</p>
<p>Vielen Dank. Grüsse, Simu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1094334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1094334</guid><dc:creator><![CDATA[simube]]></dc:creator><pubDate>Sun, 09 Jul 2006 11:06:20 GMT</pubDate></item></channel></rss>