<?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[SERVER CLIENT]]></title><description><![CDATA[<p>Hallo Leute,<br />
bin neu hier im Forum und weiß nicht genau ob ich hier im richtigen Bereich poste.<br />
Wenn nicht schon mal entschuldigung.<br />
Hab gerade angefangen mich mit Socketprog. auseinander zu setzen und bin auch prompt auf die ersten Probleme gestoßen.<br />
Habe einen Client der erstmal nichts anderes machen soll als Verbindung zum Server aufzubauen. Dies klappt auch gut solange ich z.B zum Server von google Verbindung aufbaue. Probiere ich das ganze beim meinem Server geht der Verbindungsaufbau in die Hose.<br />
Ich benutze C++ unter Codeblocks Ubuntu Linux.<br />
Hoffe es kann mir jemand weiterhelfen.<br />
Gruss</p>
<p>Client</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;sys/socket.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;string&gt;

using namespace std;

int main()
{   // Socket öffenen
    int Socket = socket(AF_INET,SOCK_STREAM,0); //(int family,int type,int Protokoll)(IPv4,TCP,0);
    if (Socket == -1){
        cout &lt;&lt; &quot;Socket konnte nicht erstellt werden&quot; &lt;&lt; endl;
        return 1;
    }

   struct sockaddr_in Verbindung;
   // Parameter festlegen;
   Verbindung.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;);
   Verbindung.sin_family=AF_INET;
   Verbindung.sin_port=htons(2000);
   int VOK = connect(Socket,(struct sockaddr *)&amp;Verbindung,sizeof(Verbindung));
     if(VOK == -1){
         cout &lt;&lt; &quot;Verbindung fehlgeschlagen&quot; &lt;&lt; endl;
         return 1;
     }
     cout &lt;&lt; &quot;Verbindung aufgebaut&quot; &lt;&lt; endl;

    return 0;
}
</code></pre>
<p>Server</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;

using namespace std;

int main()
{   // Socket öffnen;
    int Socket = socket(AF_INET,SOCK_STREAM,0);//(IPv4,TCP,0);
      if (Socket == -1){
        cout &lt;&lt; &quot;Socket konnte nicht geöffnet werden&quot; &lt;&lt; endl;
        return 1;
        }

struct sockaddr_in Verbindung;
//Parameter festlegen
Verbindung.sin_family = AF_INET;
Verbindung.sin_port = (2000);
Verbindung.sin_addr.s_addr = INADDR_ANY;

int VOK = bind(Socket,(struct sockaddr *)&amp;Verbindung,sizeof (Verbindung));
  if (VOK != 0){
      cout &lt;&lt; &quot;Verbindung fehlgeschlagen&quot;&lt;&lt; endl;
      return 1;
  }

    cout &lt;&lt;&quot;Server bereit&quot; &lt;&lt; endl;

    listen (Socket,3);
    accept(Socket,NULL,NULL);
    cout &lt;&lt; &quot;Verbindung zum Client hergestellt&quot; &lt;&lt; endl;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/253783/server-client</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 12:37:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/253783.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Nov 2009 15:15:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SERVER CLIENT on Fri, 06 Nov 2009 15:15:22 GMT]]></title><description><![CDATA[<p>Hallo Leute,<br />
bin neu hier im Forum und weiß nicht genau ob ich hier im richtigen Bereich poste.<br />
Wenn nicht schon mal entschuldigung.<br />
Hab gerade angefangen mich mit Socketprog. auseinander zu setzen und bin auch prompt auf die ersten Probleme gestoßen.<br />
Habe einen Client der erstmal nichts anderes machen soll als Verbindung zum Server aufzubauen. Dies klappt auch gut solange ich z.B zum Server von google Verbindung aufbaue. Probiere ich das ganze beim meinem Server geht der Verbindungsaufbau in die Hose.<br />
Ich benutze C++ unter Codeblocks Ubuntu Linux.<br />
Hoffe es kann mir jemand weiterhelfen.<br />
Gruss</p>
<p>Client</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;sys/socket.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;string&gt;

using namespace std;

int main()
{   // Socket öffenen
    int Socket = socket(AF_INET,SOCK_STREAM,0); //(int family,int type,int Protokoll)(IPv4,TCP,0);
    if (Socket == -1){
        cout &lt;&lt; &quot;Socket konnte nicht erstellt werden&quot; &lt;&lt; endl;
        return 1;
    }

   struct sockaddr_in Verbindung;
   // Parameter festlegen;
   Verbindung.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;);
   Verbindung.sin_family=AF_INET;
   Verbindung.sin_port=htons(2000);
   int VOK = connect(Socket,(struct sockaddr *)&amp;Verbindung,sizeof(Verbindung));
     if(VOK == -1){
         cout &lt;&lt; &quot;Verbindung fehlgeschlagen&quot; &lt;&lt; endl;
         return 1;
     }
     cout &lt;&lt; &quot;Verbindung aufgebaut&quot; &lt;&lt; endl;

    return 0;
}
</code></pre>
<p>Server</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;

using namespace std;

int main()
{   // Socket öffnen;
    int Socket = socket(AF_INET,SOCK_STREAM,0);//(IPv4,TCP,0);
      if (Socket == -1){
        cout &lt;&lt; &quot;Socket konnte nicht geöffnet werden&quot; &lt;&lt; endl;
        return 1;
        }

struct sockaddr_in Verbindung;
//Parameter festlegen
Verbindung.sin_family = AF_INET;
Verbindung.sin_port = (2000);
Verbindung.sin_addr.s_addr = INADDR_ANY;

int VOK = bind(Socket,(struct sockaddr *)&amp;Verbindung,sizeof (Verbindung));
  if (VOK != 0){
      cout &lt;&lt; &quot;Verbindung fehlgeschlagen&quot;&lt;&lt; endl;
      return 1;
  }

    cout &lt;&lt;&quot;Server bereit&quot; &lt;&lt; endl;

    listen (Socket,3);
    accept(Socket,NULL,NULL);
    cout &lt;&lt; &quot;Verbindung zum Client hergestellt&quot; &lt;&lt; endl;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1804466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1804466</guid><dc:creator><![CDATA[golfkrieg2000]]></dc:creator><pubDate>Fri, 06 Nov 2009 15:15:22 GMT</pubDate></item><item><title><![CDATA[Reply to SERVER CLIENT on Fri, 06 Nov 2009 15:29:33 GMT]]></title><description><![CDATA[<p>ich bin der Sprache C++ nicht so mächtig aber vllt hast du vergessen den Port auch im Router freizugeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1804473</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1804473</guid><dc:creator><![CDATA[Siraja]]></dc:creator><pubDate>Fri, 06 Nov 2009 15:29:33 GMT</pubDate></item><item><title><![CDATA[Reply to SERVER CLIENT on Fri, 06 Nov 2009 16:17:00 GMT]]></title><description><![CDATA[<p>Muss beim Server ebenfalls htons(2000) heißen.<br />
Am Router kann's nicht liegen, der wird nicht gefragt, wenn man mit localhost kommuniziert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1804502</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1804502</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Fri, 06 Nov 2009 16:17:00 GMT</pubDate></item><item><title><![CDATA[Reply to SERVER CLIENT on Fri, 06 Nov 2009 16:31:32 GMT]]></title><description><![CDATA[<p>Vielen dank..<br />
htons() hat gefehlt hab ich übersehen. <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="😉"
    /> Jetzt funktioniert es.</p>
<p>Nochmal danke für die schnelle Beantwortung. Echt ein gutes Forum.<br />
Gruss</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1804511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1804511</guid><dc:creator><![CDATA[golfkrieg2000]]></dc:creator><pubDate>Fri, 06 Nov 2009 16:31:32 GMT</pubDate></item><item><title><![CDATA[Reply to SERVER CLIENT on Fri, 06 Nov 2009 18:39:52 GMT]]></title><description><![CDATA[<p>sry hab die 127.0.0.1 übersehen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1804585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1804585</guid><dc:creator><![CDATA[Siraja]]></dc:creator><pubDate>Fri, 06 Nov 2009 18:39:52 GMT</pubDate></item></channel></rss>