<?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[(win)Socket-Probleme]]></title><description><![CDATA[<p>Moin,</p>
<p>ich fange gerade an mich mit Netzwerkfunktionen auseinander zu setzen und wollte erstmal nen kleines Testprogramm schreiben, welches einfachen Daten verschicken kann. Es ist leider bis jetzt erst hablfertig, aber trotzdem hier mal der Code:</p>
<pre><code>#include &lt;winsock.h&gt;
#include &lt;iostream.h&gt;

void WSAInit(void)
{
	WORD wVersionReg = MAKEWORD(1, 1);
	WSADATA wsaData;
	if (int err = WSAStartup(wVersionReg, &amp;wsaData) != 0)
    {
		cout &lt;&lt;&quot;Fehler: Initialisieren - WinSock.dll!&quot;;
    }
}

void main()
{
	int schluss;

	cout &lt;&lt; &quot;TCP-IP-TEST-PROGRAMM\nVersion1.0\n\n&quot;;

	//Winsocket initialisieren
	WSAInit();
	cout &lt;&lt; &quot;WINSOCKET initialisiert\n&quot;;

	//Datenelement für IP und Port erstellen
	struct sockaddr_in AdrClient;

	AdrClient.sin_family = AF_INET;	// Wie wird connected (standart)
	AdrClient.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;); // Was wird connected
	AdrClient.sin_port = 5002; // Über welchen Port

	cout &lt;&lt; &quot;Client-Daten gesetzt\n&quot;;

	//Sockets erstellen
	int client;

	//Sockets mit Daten füttern
	if ((client = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)  //Typ der Verbindung/Socket festlegen
		cout &lt;&lt; &quot;Fehler beim Erstellen des Client-Socket!\n&quot;;
    else
		cout &lt;&lt; &quot;Client-Socket initialisiert\n&quot;;

	//Client-Socket connecten
	if ( connect (client, (struct sockaddr *) &amp;AdrClient, sizeof(AdrClient)) == SOCKET_ERROR)
     cout &lt;&lt; &quot;Fehler beim Connecten mit Server!\n&quot;;
	else
		cout &lt;&lt; &quot;Client mit Server connected\n&quot;;

	closesocket(client);	
	cout &lt;&lt; &quot;Sockets geschlossen!\n&quot;;

	cin &gt;&gt; schluss;
}
</code></pre>
<p>Nun möchte ich auf nen Server connecten.<br />
Deswegen geb ich ja einen bestimmt Port an (in AdrClient.sin_port).<br />
Problem ist, dass die connect() nur sockaddr * annimmt, aber kein sockaddr_in, den ich benutze um den Port zu übermitteln.<br />
Jetzt beim Umwandeln fallen natürlich sin_port und Co. weg, sodass ein willkürlicher Port genommen wird.</p>
<p>In den Tutorials die ich habe klappt es mal mit und mal ohne Umwandlung, bei mir geht beides nicht.</p>
<p>Jemand ne Idee was ich falsch mache??</p>
<p>Dank im Voraus!</p>
<p>Gruß<br />
chackie-lee</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/109155/win-socket-probleme</link><generator>RSS for Node</generator><lastBuildDate>Tue, 30 Jun 2026 11:22:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/109155.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 07 May 2005 08:56:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to (win)Socket-Probleme on Sat, 07 May 2005 08:56:23 GMT]]></title><description><![CDATA[<p>Moin,</p>
<p>ich fange gerade an mich mit Netzwerkfunktionen auseinander zu setzen und wollte erstmal nen kleines Testprogramm schreiben, welches einfachen Daten verschicken kann. Es ist leider bis jetzt erst hablfertig, aber trotzdem hier mal der Code:</p>
<pre><code>#include &lt;winsock.h&gt;
#include &lt;iostream.h&gt;

void WSAInit(void)
{
	WORD wVersionReg = MAKEWORD(1, 1);
	WSADATA wsaData;
	if (int err = WSAStartup(wVersionReg, &amp;wsaData) != 0)
    {
		cout &lt;&lt;&quot;Fehler: Initialisieren - WinSock.dll!&quot;;
    }
}

void main()
{
	int schluss;

	cout &lt;&lt; &quot;TCP-IP-TEST-PROGRAMM\nVersion1.0\n\n&quot;;

	//Winsocket initialisieren
	WSAInit();
	cout &lt;&lt; &quot;WINSOCKET initialisiert\n&quot;;

	//Datenelement für IP und Port erstellen
	struct sockaddr_in AdrClient;

	AdrClient.sin_family = AF_INET;	// Wie wird connected (standart)
	AdrClient.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;); // Was wird connected
	AdrClient.sin_port = 5002; // Über welchen Port

	cout &lt;&lt; &quot;Client-Daten gesetzt\n&quot;;

	//Sockets erstellen
	int client;

	//Sockets mit Daten füttern
	if ((client = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)  //Typ der Verbindung/Socket festlegen
		cout &lt;&lt; &quot;Fehler beim Erstellen des Client-Socket!\n&quot;;
    else
		cout &lt;&lt; &quot;Client-Socket initialisiert\n&quot;;

	//Client-Socket connecten
	if ( connect (client, (struct sockaddr *) &amp;AdrClient, sizeof(AdrClient)) == SOCKET_ERROR)
     cout &lt;&lt; &quot;Fehler beim Connecten mit Server!\n&quot;;
	else
		cout &lt;&lt; &quot;Client mit Server connected\n&quot;;

	closesocket(client);	
	cout &lt;&lt; &quot;Sockets geschlossen!\n&quot;;

	cin &gt;&gt; schluss;
}
</code></pre>
<p>Nun möchte ich auf nen Server connecten.<br />
Deswegen geb ich ja einen bestimmt Port an (in AdrClient.sin_port).<br />
Problem ist, dass die connect() nur sockaddr * annimmt, aber kein sockaddr_in, den ich benutze um den Port zu übermitteln.<br />
Jetzt beim Umwandeln fallen natürlich sin_port und Co. weg, sodass ein willkürlicher Port genommen wird.</p>
<p>In den Tutorials die ich habe klappt es mal mit und mal ohne Umwandlung, bei mir geht beides nicht.</p>
<p>Jemand ne Idee was ich falsch mache??</p>
<p>Dank im Voraus!</p>
<p>Gruß<br />
chackie-lee</p>
]]></description><link>https://www.c-plusplus.net/forum/post/783282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/783282</guid><dc:creator><![CDATA[chackie-lee]]></dc:creator><pubDate>Sat, 07 May 2005 08:56:23 GMT</pubDate></item><item><title><![CDATA[Reply to (win)Socket-Probleme on Sat, 07 May 2005 09:02:49 GMT]]></title><description><![CDATA[<p>Ok, hab den Fehler schon selber gefunden!</p>
<p>Es fehlt das htons(port) bei AdrClient.sin_port = 5002;<br />
Also:</p>
<pre><code>AdrClient.sin_port = htons(5002);
</code></pre>
<p>Gruß<br />
chackie-lee</p>
]]></description><link>https://www.c-plusplus.net/forum/post/783290</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/783290</guid><dc:creator><![CDATA[chackie-lee]]></dc:creator><pubDate>Sat, 07 May 2005 09:02:49 GMT</pubDate></item><item><title><![CDATA[Reply to (win)Socket-Probleme on Sat, 07 May 2005 09:35:26 GMT]]></title><description><![CDATA[<p>chackie-lee schrieb:</p>
<blockquote>
<p>htons</p>
</blockquote>
<p>host-to-network-short</p>
]]></description><link>https://www.c-plusplus.net/forum/post/783309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/783309</guid><dc:creator><![CDATA[Socke]]></dc:creator><pubDate>Sat, 07 May 2005 09:35:26 GMT</pubDate></item><item><title><![CDATA[Reply to (win)Socket-Probleme on Sun, 08 May 2005 08:55:53 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=403" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=4" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/783844</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/783844</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sun, 08 May 2005 08:55:53 GMT</pubDate></item></channel></rss>