<?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[Frage zur winsocket ?!?]]></title><description><![CDATA[<p>nAbend, also ich habe mir mal so gedacht da ich heute abend eh nichts vorhabe beschäftige ich mich mal nen bissel mit WINSOCK. Also eigentlich läuft alles ganz reibungslos bislang noch keine probleme, ich habe WinSock gestartet, einen client socket ertstellt und was mich wundert und deshlb auch der grund fuer meinen post, ich habe versucht mich mit den client auf einen server zu verbinen. Das komische ist, ich habe als ip die 127.0.0.1 fuer meinen eigenen PC angegeben und einen test prot 12345. eigentlich muesste mir die anwendung ja einen fehler melden da ich sicher kein port habe mit 12345, ich habe auch andere ports ausprobiert und zu allen konnte ich mich verbinden wie ist denn das möglich?<br />
Hier mein quelltext, vielleicht ist ja was falsch:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;

int startWinsock();                                                 // Fkt. to start WinSock

SOCKET client_s;                                                    // ClientSocket var
SOCKADDR_IN cAddr;                                                  // ClientAddress var;
long rc;
int main() {

    rc = startWinsock();                                            // Var. to proof status
        if( rc != 0 ) {

            printf( &quot; Fehler: startWinsock, fehler code: %d\n&quot;, rc );
            getchar();
            return 1;
        }
        else {

            printf( &quot; Winsock gestartet!\n&quot; );
        }

  client_s = socket( AF_INET, SOCK_STREAM, 0 );
    if( client_s == INVALID_SOCKET ) {

        printf( &quot; Error: Couldn't create client socket,%d\n&quot;,
                WSAGetLastError() );
        getchar();
        return 1;
    }
    else {

        printf( &quot; Client socket was successfully create!\n&quot; );
    }

   memset( &amp;cAddr, 0, sizeof( cAddr ) );

       cAddr.sin_family = AF_INET;
       cAddr.sin_port = htons( 12345 );
       cAddr.sin_addr.s_addr = inet_addr( &quot;127.0.0.1&quot; );           // Add (127.0.0.1) IP immer zum eigenen PC

  rc = connect( client_s, (SOCKADDR*) &amp;cAddr, sizeof( cAddr ) );
    if( client_s == SOCKET_ERROR ) {

        printf( &quot; Error: Couldn't connect to Server-Address. %d &quot;, inet_addr );
        getchar();
        return 1;
    }
    else {

        printf( &quot; All right, the connection to Server is fine!\n&quot; );
    }
  getchar();
  return 0;

}
int startWinsock() {

  WSADATA wsa;
  return WSAStartup( MAKEWORD( 2, 0 ), &amp;wsa );                      // Start WinSock!
}
</code></pre>
<p>Ich benutze den BCB6 als entwicklungsumgebung. Weiter wollte ich auch noch die lib WINSOCK2.h include doch da kams dann zu einer latte an fehlern:</p>
<pre><code>[C++ Error] winsock2.h(109): E2238 Multiple declaration for 'fd_set'
[C++ Error] winsock.h(54): E2344 Earlier declaration of 'fd_set'
[C++ Error] winsock2.h(112): E2146 Need an identifier to declare
[C++ Warning] winsock2.h(144): W8017 Redefinition of 'FD_SET' is not identical
[C++ Error] winsock2.h(153): E2238 Multiple declaration for 'timeval'
[C++ Error] winsock.h(97): E2344 Earlier declaration of 'timeval'
[C++ Error] winsock2.h(209): E2238 Multiple declaration for 'hostent'
[C++ Error] winsock.h(153): E2344 Earlier declaration of 'hostent'
[C++ Error] winsock2.h(222): E2238 Multiple declaration for 'netent'
[C++ Error] winsock.h(166): E2344 Earlier declaration of 'netent'
[C++ Error] winsock2.h(229): E2238 Multiple declaration for 'servent'
[C++ Error] winsock.h(173): E2344 Earlier declaration of 'servent'
[C++ Error] winsock2.h(241): E2238 Multiple declaration for 'protoent'
[C++ Error] winsock.h(185): E2344 Earlier declaration of 'protoent'
[C++ Error] winsock2.h(327): E2238 Multiple declaration for 'in_addr'
[C++ Error] winsock.h(269): E2344 Earlier declaration of 'in_addr'
[C++ Error] winsock2.h(385): E2238 Multiple declaration for 'sockaddr_in'
[C++ Error] winsock.h(319): E2344 Earlier declaration of 'sockaddr_in'
[C++ Error] winsock2.h(395): E2238 Multiple declaration for 'WSAData'
[C++ Error] winsock.h(329): E2344 Earlier declaration of 'WSAData'
[C++ Error] winsock2.h(411): E2146 Need an identifier to declare
[C++ Warning] winsock2.h(455): W8017 Redefinition of 'SO_DONTLINGER' is not identical
[C++ Warning] winsock2.h(512): W8017 Redefinition of 'AF_IPX' is not identical
[C++ Warning] winsock2.h(540): W8017 Redefinition of 'AF_MAX' is not identical
[C++ Error] winsock2.h(546): E2238 Multiple declaration for 'sockaddr'
[C++ Error] winsock.h(492): E2344 Earlier declaration of 'sockaddr'
[C++ Error] winsock2.h(586): E2238 Multiple declaration for 'sockproto'
[C++ Error] winsock.h(501): E2344 Earlier declaration of 'sockproto'
[C++ Error] winsock2.h(625): E2238 Multiple declaration for 'linger'
[C++ Error] winsock2.h(625): E2228 Too many error or warning messages
</code></pre>
<p>wieso ist alles doppelt deklariert?<br />
Waer nett wenn ihr mir da mal etwas auf die sprünge helfen könntet, Thanx.</p>
<p>Gruß Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/167877/frage-zur-winsocket</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 14:11:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/167877.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 15 Dec 2006 21:26:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zur winsocket ?!? on Fri, 15 Dec 2006 21:26:42 GMT]]></title><description><![CDATA[<p>nAbend, also ich habe mir mal so gedacht da ich heute abend eh nichts vorhabe beschäftige ich mich mal nen bissel mit WINSOCK. Also eigentlich läuft alles ganz reibungslos bislang noch keine probleme, ich habe WinSock gestartet, einen client socket ertstellt und was mich wundert und deshlb auch der grund fuer meinen post, ich habe versucht mich mit den client auf einen server zu verbinen. Das komische ist, ich habe als ip die 127.0.0.1 fuer meinen eigenen PC angegeben und einen test prot 12345. eigentlich muesste mir die anwendung ja einen fehler melden da ich sicher kein port habe mit 12345, ich habe auch andere ports ausprobiert und zu allen konnte ich mich verbinden wie ist denn das möglich?<br />
Hier mein quelltext, vielleicht ist ja was falsch:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;

int startWinsock();                                                 // Fkt. to start WinSock

SOCKET client_s;                                                    // ClientSocket var
SOCKADDR_IN cAddr;                                                  // ClientAddress var;
long rc;
int main() {

    rc = startWinsock();                                            // Var. to proof status
        if( rc != 0 ) {

            printf( &quot; Fehler: startWinsock, fehler code: %d\n&quot;, rc );
            getchar();
            return 1;
        }
        else {

            printf( &quot; Winsock gestartet!\n&quot; );
        }

  client_s = socket( AF_INET, SOCK_STREAM, 0 );
    if( client_s == INVALID_SOCKET ) {

        printf( &quot; Error: Couldn't create client socket,%d\n&quot;,
                WSAGetLastError() );
        getchar();
        return 1;
    }
    else {

        printf( &quot; Client socket was successfully create!\n&quot; );
    }

   memset( &amp;cAddr, 0, sizeof( cAddr ) );

       cAddr.sin_family = AF_INET;
       cAddr.sin_port = htons( 12345 );
       cAddr.sin_addr.s_addr = inet_addr( &quot;127.0.0.1&quot; );           // Add (127.0.0.1) IP immer zum eigenen PC

  rc = connect( client_s, (SOCKADDR*) &amp;cAddr, sizeof( cAddr ) );
    if( client_s == SOCKET_ERROR ) {

        printf( &quot; Error: Couldn't connect to Server-Address. %d &quot;, inet_addr );
        getchar();
        return 1;
    }
    else {

        printf( &quot; All right, the connection to Server is fine!\n&quot; );
    }
  getchar();
  return 0;

}
int startWinsock() {

  WSADATA wsa;
  return WSAStartup( MAKEWORD( 2, 0 ), &amp;wsa );                      // Start WinSock!
}
</code></pre>
<p>Ich benutze den BCB6 als entwicklungsumgebung. Weiter wollte ich auch noch die lib WINSOCK2.h include doch da kams dann zu einer latte an fehlern:</p>
<pre><code>[C++ Error] winsock2.h(109): E2238 Multiple declaration for 'fd_set'
[C++ Error] winsock.h(54): E2344 Earlier declaration of 'fd_set'
[C++ Error] winsock2.h(112): E2146 Need an identifier to declare
[C++ Warning] winsock2.h(144): W8017 Redefinition of 'FD_SET' is not identical
[C++ Error] winsock2.h(153): E2238 Multiple declaration for 'timeval'
[C++ Error] winsock.h(97): E2344 Earlier declaration of 'timeval'
[C++ Error] winsock2.h(209): E2238 Multiple declaration for 'hostent'
[C++ Error] winsock.h(153): E2344 Earlier declaration of 'hostent'
[C++ Error] winsock2.h(222): E2238 Multiple declaration for 'netent'
[C++ Error] winsock.h(166): E2344 Earlier declaration of 'netent'
[C++ Error] winsock2.h(229): E2238 Multiple declaration for 'servent'
[C++ Error] winsock.h(173): E2344 Earlier declaration of 'servent'
[C++ Error] winsock2.h(241): E2238 Multiple declaration for 'protoent'
[C++ Error] winsock.h(185): E2344 Earlier declaration of 'protoent'
[C++ Error] winsock2.h(327): E2238 Multiple declaration for 'in_addr'
[C++ Error] winsock.h(269): E2344 Earlier declaration of 'in_addr'
[C++ Error] winsock2.h(385): E2238 Multiple declaration for 'sockaddr_in'
[C++ Error] winsock.h(319): E2344 Earlier declaration of 'sockaddr_in'
[C++ Error] winsock2.h(395): E2238 Multiple declaration for 'WSAData'
[C++ Error] winsock.h(329): E2344 Earlier declaration of 'WSAData'
[C++ Error] winsock2.h(411): E2146 Need an identifier to declare
[C++ Warning] winsock2.h(455): W8017 Redefinition of 'SO_DONTLINGER' is not identical
[C++ Warning] winsock2.h(512): W8017 Redefinition of 'AF_IPX' is not identical
[C++ Warning] winsock2.h(540): W8017 Redefinition of 'AF_MAX' is not identical
[C++ Error] winsock2.h(546): E2238 Multiple declaration for 'sockaddr'
[C++ Error] winsock.h(492): E2344 Earlier declaration of 'sockaddr'
[C++ Error] winsock2.h(586): E2238 Multiple declaration for 'sockproto'
[C++ Error] winsock.h(501): E2344 Earlier declaration of 'sockproto'
[C++ Error] winsock2.h(625): E2238 Multiple declaration for 'linger'
[C++ Error] winsock2.h(625): E2228 Too many error or warning messages
</code></pre>
<p>wieso ist alles doppelt deklariert?<br />
Waer nett wenn ihr mir da mal etwas auf die sprünge helfen könntet, Thanx.</p>
<p>Gruß Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1192721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1192721</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Fri, 15 Dec 2006 21:26:42 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur winsocket ?!? on Fri, 15 Dec 2006 21:45:11 GMT]]></title><description><![CDATA[<p>include winsock2.h VOR include windows.h</p>
<p>oder umgekehrt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1192727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1192727</guid><dc:creator><![CDATA[PhoeNix_FasT]]></dc:creator><pubDate>Fri, 15 Dec 2006 21:45:11 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur winsocket ?!? on Fri, 15 Dec 2006 22:41:37 GMT]]></title><description><![CDATA[<p>oha .. so gehts.. winsock2 vor windosgeht -.- komisch... ber woran liegtdes nun das mein client trotz fallschen prot eine verbindung aufbaut?</p>
<p>Gruß Tobi :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1192748</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1192748</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Fri, 15 Dec 2006 22:41:37 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur winsocket ?!? on Sat, 16 Dec 2006 00:13:30 GMT]]></title><description><![CDATA[<p>T0bi schrieb:</p>
<blockquote>
<p>aber woran liegtdes nun das mein client trotz fallschen prot eine verbindung aufbaut?</p>
</blockquote>
<p>Tipp: Prüfe nicht den Wert des Sockets, sondern den Rückgabewert von connect() auf SOCKET_ERROR <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=";D"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1192768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1192768</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Sat, 16 Dec 2006 00:13:30 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur winsocket ?!? on Sat, 16 Dec 2006 11:10:42 GMT]]></title><description><![CDATA[<p>ahh danke daran hats gelegen <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>
<p>Gruß Tobi :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1192882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1192882</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Sat, 16 Dec 2006 11:10:42 GMT</pubDate></item></channel></rss>