<?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[socket problem -&amp;gt; mehrere clients mit threads]]></title><description><![CDATA[<p>ich beschäftige mich grade zum ersten mal mit sockets. der gesamte quellcode ist im grunde aus stücken zusammengeflickt, da ich mich währed des schreibens &quot;weitergebildet&quot; habe. also ich möchte nicht sona antwort haben wie &quot;hmm total beschissen geschrieben...ern erstmal richtig c&quot; oder so<br />
danke.</p>
<p>Das problem ist, das ich wenn ich mit nem client connecte auf dem client nur ne meldung kriege &quot;verbindung zu ... hergestellt&quot; beim serv passiert aber folgendes:</p>
<pre><code>-&gt;Neuer Socket erstellt auf Platz 0
-&gt;Im Listenmodus(warte auf client...)
-&gt;Client Verbunden!
-&gt;Neuer Socket erstellt auf Platz 1
Client verloren...
</code></pre>
<p>auch der datenaustausch funktioniert nurnoch vom server zum client aber nichtmehr vom client zum server...<br />
comments im sourcecode lesen für weitere infos!<br />
danke für jede hilfe...(btw...hatte nur n tut zur hand welches mehrere clients per select verwaltet, wollte es aber mit threads machen, habs deswegen selbst mal probiert ^^)</p>
<pre><code class="language-cpp">//dies ist der server...
#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;fstream.h&gt;
#include &quot;resource.h&quot;;
#define MAX_CLIENTS 10
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK MakeProc (HWND, UINT, WPARAM, LPARAM);
unsigned long RcvProc();
unsigned long RcvProcS();
HWND dlgBox;
///-------------------
//...
//...
//hier sind funktionen....
///-------------------

	class MakeSockets
	{
	private:
		int status;
		SOCKET s;
		SOCKADDR_IN addr;
		long rc;
	public:
		MakeSockets()
		{
			status = 0;
		}
		void ConnectSock(char *IPAdresse)
		{
			rc=startWinsock();
			// Winsock starten
			if(rc!=0)
			{
				//FEHLER! code in rc drin...
			}
			else
			{
				//OK
			}
			// Socket erstellen
			s=socket(AF_INET,SOCK_STREAM,0);
			if(s==INVALID_SOCKET)
			{
				closesocket(s);
			}
			else
			{
				//socket erstellt
			}
			memset(&amp;addr,0,sizeof(SOCKADDR_IN)); // zuerst alles auf 0 setzten 
			addr.sin_family=AF_INET;
			addr.sin_port=htons(12345); // wir verwenden mal port 12345
			addr.sin_addr.s_addr=inet_addr(IPAdresse); // zielrechner ist unser eigener
			rc=connect(s,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR));
			if(rc==SOCKET_ERROR)
			{
				//Fehler: connect gescheitert, fehler code: %d\n&quot;,WSAGetLastError()
				closesocket(s);
				status = 2;
			}
			else
			{
				//Verbunden mit 127.0.0.1..
				status = 1;
			}
		}
		int GiveStatus()
		{
			return status;
		}
		char *recieve()
		{
			char *buffer = new char[256];
			rc=recv(s,buffer,256,0);
			buffer[rc] = '\0';
			if(rc==0 || rc==SOCKET_ERROR)
				return &quot;&quot;;
			return buffer;
		}
		void sendData(char *strToSend)
		{
			rc=send(s,strToSend,strlen(strToSend),0);
		}
		void end()
		{
			closesocket(s);
			WSACleanup();
		}
	};
	class MakeSocketsServer
	{
	private:
		SOCKET acceptSocket;
		SOCKET connectedSocket[MAX_CLIENTS];
		long rc;
		int port;
		SOCKADDR_IN addr;
	public:
		MakeSocketsServer()
		{
			// Winsock starten
			rc=startWinsock();
			// Socket erstellen
		for(int i=0;i&lt;MAX_CLIENTS;i++) 
		  {
			connectedSocket[i]=INVALID_SOCKET;
		  }
		}
		void setPort(int portnum)
		{
			port = portnum;
		}
		int CreateSock(SOCKET x)
		{
			int ret = -1;
			for(int i=0;i&lt;MAX_CLIENTS;++i)
			{
				if(connectedSocket[i] == INVALID_SOCKET)
				{
					connectedSocket[i] = x;
					addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;-&gt;Neuer Socket erstellt auf Platz &quot;,itos(i)));
					ret = i;
					break;
				}
				if(i == MAX_CLIENTS-1)
				{
					PostQuitMessage(0);
				}
			}
			acceptSocket=socket(AF_INET,SOCK_STREAM,0);
			if(acceptSocket==INVALID_SOCKET)
			{
				closesocket(acceptSocket);
			}
			else
			{
				//socket erstellt
			}
			memset(&amp;addr,0,sizeof(SOCKADDR_IN));
			addr.sin_family=AF_INET;
			addr.sin_port=htons(port);
			addr.sin_addr.s_addr=INADDR_ANY;
			rc=bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN));
			if(rc==SOCKET_ERROR)
			{
				//Fehler: bind, fehler code: %d\n&quot;,WSAGetLastError()...
				closesocket(acceptSocket);
			}
			else
			{
				//Socket an port 12345 gebunden
			}
			return ret;
		}
		void listenS(int i)
		{
			rc=listen(acceptSocket,10);
			if(rc==SOCKET_ERROR)
			{
				//Fehler: listen, fehler code: %d\n&quot;,WSAGetLastError()
				closesocket(acceptSocket);
			}
			else
			{	
				//acceptSocket ist im listen Modus....
				addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;-&gt;Im Listenmodus(warte auf client...)&quot;);
			}
			connectedSocket[i]=accept(acceptSocket,NULL,NULL);
			if(connectedSocket[i]==INVALID_SOCKET)
			{
				//Fehler: accept, fehler code: %d\n&quot;,WSAGetLastError()...
				closesocket(acceptSocket);
			}
			else
			{
				addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;-&gt;Client Verbunden!&quot;);
///-------------------------------------------------
//Hier möchte ich, das jedesmal wenn ein client neu connected ein neuer thread erstellt wird, der auf den nächsten client wartet.
//wenn ich das weglasse, dann kann ich mit einem client connecten und daten austauschen...aber halt nur mit einem...
				HANDLE hAcceptThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RcvProcS, NULL, NULL, NULL);
//kann das problem sei, das die klasse immer nur ein listen verwalten kann?
//--------------------------------------------------
			}
		}
		int answer(int i)
		{
				char *buffer = new char[256];
				rc=recv(connectedSocket[i],buffer,256,0);
				buffer[rc] = '\0';
				if(rc!=0 &amp;&amp; rc!=SOCKET_ERROR)
				{
					int lineCode = getStrCode(buffer);
					char *lineStr = new char[strlen(buffer)-3];
					lineStr = getLwC(buffer);
					switch(lineCode)
					{
					case 0:
						addLine(GetDlgItem(dlgBox,IDC_SHOW),lineStr);
						break;
					case 1:
						addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;x changes name...&quot;);
						break;
					}
					delete [] buffer;
				}
				else
				{
					return 1;
				}
				return 0;
		}
		void sendData(char *strToSend, int i)
		{
			rc=send(connectedSocket[i],strToSend,strlen(strToSend),0);
		}
		void end()
		{
			for(int i=0;i&lt;MAX_CLIENTS;++i)
				closesocket(connectedSocket[i]);
			closesocket(acceptSocket);
			WSACleanup();
		}
		void endCon(int i)
		{
			closesocket(connectedSocket[i]);
		}
		bool isValid(int i)
		{
			if(connectedSocket[i] == INVALID_SOCKET)
				return FALSE;
			return TRUE;
		}
};
MakeSockets Sock;
MakeSocketsServer SockServer;
//Deklaration der Windows-Nachrichten-Prozedur 
///---------------------WIndow krams.......
		HANDLE hAcceptThread;
		switch (message) 
		{
			case WM_INITDIALOG:
				ShowWindow(hwnd, SW_SHOWNORMAL);
				dlgBox=hwnd;
				return TRUE;
			case WM_COMMAND: 
            	if(LOWORD(wParam) == IDOK)
				{	
					char *ip = new char[GetEditTextLength(GetDlgItem(hwnd,IDC_IPADDRESS))];
					ip = WindowText(GetDlgItem(hwnd,IDC_IPADDRESS));
					Sock.ConnectSock(ip);
					if(Sock.GiveStatus() == 1)
					{
						addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;Konnte zu &quot;,CombinChars(ip,&quot; verbinden&quot;)));
					}
					else if(Sock.GiveStatus() == 2)
					{
						addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;Konnte nicht zu &quot;,CombinChars(ip,&quot; verbinden&quot;)));
					}
					hAcceptThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RcvProc, NULL, NULL, NULL);
				}
				if(LOWORD(wParam) == ID_SEND)
				{
					char *buf = new char[GetEditTextLength(GetDlgItem(hwnd,IDC_TOSEND))-3];
					buf = WindowText(GetDlgItem(hwnd,IDC_TOSEND));
					Sock.sendData(CombinChars(&quot;001&quot;,buf));
					addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;[me]:&quot;,buf));
				}
				return TRUE;
			case WM_CLOSE:
				Sock.end();
				EndDialog(hwnd,0);
		}  
		return FALSE;
	}
	LRESULT CALLBACK MakeProcS (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
	{
		HANDLE hAcceptThread;
		switch (message) 
		{
			case WM_INITDIALOG:
				dlgBox=hwnd;
				return TRUE;
			case WM_COMMAND: 
            	if(LOWORD(wParam) == IDOK)
				{	
					char *port = new char[GetEditTextLength(GetDlgItem(hwnd,IDC_PORT))];
					port = WindowText(GetDlgItem(hwnd,IDC_PORT));
					DWORD  idAcceptThread;
					SockServer.setPort(atof(port));
					hAcceptThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RcvProcS, NULL, NULL, &amp;idAcceptThread);
				}
				if(LOWORD(wParam) == ID_SEND)
				{
					char *buf = new char[GetEditTextLength(GetDlgItem(hwnd,IDC_TOSEND))];
					buf = WindowText(GetDlgItem(hwnd,IDC_TOSEND));
					for(int x=0;x&lt;MAX_CLIENTS;++x)
					{
						if(SockServer.isValid(x))
							SockServer.sendData(buf,x);
					}
					addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;[me]:&quot;,buf));
				}
				return TRUE;
			case WM_CLOSE:
				SockServer.end();
				EndDialog(hwnd,0);
		}  
		return FALSE;
	}
	LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
	{ 
	switch (message) 
	{ 
	case WM_CREATE:
		if(LOWORD(wParam) == 0) 
		{

		}
		return 0 ;
	case WM_COMMAND:
		if(LOWORD(wParam) == ID_CONNECT)
		{
			DialogBox(hInst,(LPCTSTR)IDD_DIALOG, hwnd, (DLGPROC)MakeProc);
		}
		if(LOWORD(wParam) == ID_SERVER_ERSTELLEN)
		{
			DialogBox(hInst,(LPCTSTR)IDD_DIALOGS, hwnd, (DLGPROC)MakeProcS);
		}
		return 0;
	case WM_SIZE:
		return 0;
	case WM_CLOSE:
		DestroyWindow(hwnd);
	case WM_DESTROY:
		  PostQuitMessage (0);
		  return 0;
	}

return DefWindowProc (hwnd, message, wParam, lParam); 
} 

unsigned long RcvProc()
{
	while(1)
	{
		char *tmp = new char[256];
		tmp = Sock.recieve();
		if(tmp != &quot;&quot;)
			addLine(GetDlgItem(dlgBox,IDC_SHOW),tmp);
		else
		{
			addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;Connection Error&quot;);
			Sock.end();
			return 0;
		}
	}
return 0; 
}
unsigned long RcvProcS()
{
	SOCKET theSocket;
	int sockNum;
	sockNum = SockServer.CreateSock(theSocket);
	SockServer.listenS(sockNum);
	int x = 0;
	while(x==0)
	{
		x = SockServer.answer(sockNum);
	}
	SockServer.endCon(sockNum);
	addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;Client verloren...&quot;);
	return 0;

}
</code></pre>
<p>edit wer n tut hat zu sockets in winAPI mit threads..bitte linken <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/topic/79182/socket-problem-gt-mehrere-clients-mit-threads</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 18:30:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/79182.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Jul 2004 15:13:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Thu, 08 Jul 2004 15:36:12 GMT]]></title><description><![CDATA[<p>ich beschäftige mich grade zum ersten mal mit sockets. der gesamte quellcode ist im grunde aus stücken zusammengeflickt, da ich mich währed des schreibens &quot;weitergebildet&quot; habe. also ich möchte nicht sona antwort haben wie &quot;hmm total beschissen geschrieben...ern erstmal richtig c&quot; oder so<br />
danke.</p>
<p>Das problem ist, das ich wenn ich mit nem client connecte auf dem client nur ne meldung kriege &quot;verbindung zu ... hergestellt&quot; beim serv passiert aber folgendes:</p>
<pre><code>-&gt;Neuer Socket erstellt auf Platz 0
-&gt;Im Listenmodus(warte auf client...)
-&gt;Client Verbunden!
-&gt;Neuer Socket erstellt auf Platz 1
Client verloren...
</code></pre>
<p>auch der datenaustausch funktioniert nurnoch vom server zum client aber nichtmehr vom client zum server...<br />
comments im sourcecode lesen für weitere infos!<br />
danke für jede hilfe...(btw...hatte nur n tut zur hand welches mehrere clients per select verwaltet, wollte es aber mit threads machen, habs deswegen selbst mal probiert ^^)</p>
<pre><code class="language-cpp">//dies ist der server...
#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;fstream.h&gt;
#include &quot;resource.h&quot;;
#define MAX_CLIENTS 10
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK MakeProc (HWND, UINT, WPARAM, LPARAM);
unsigned long RcvProc();
unsigned long RcvProcS();
HWND dlgBox;
///-------------------
//...
//...
//hier sind funktionen....
///-------------------

	class MakeSockets
	{
	private:
		int status;
		SOCKET s;
		SOCKADDR_IN addr;
		long rc;
	public:
		MakeSockets()
		{
			status = 0;
		}
		void ConnectSock(char *IPAdresse)
		{
			rc=startWinsock();
			// Winsock starten
			if(rc!=0)
			{
				//FEHLER! code in rc drin...
			}
			else
			{
				//OK
			}
			// Socket erstellen
			s=socket(AF_INET,SOCK_STREAM,0);
			if(s==INVALID_SOCKET)
			{
				closesocket(s);
			}
			else
			{
				//socket erstellt
			}
			memset(&amp;addr,0,sizeof(SOCKADDR_IN)); // zuerst alles auf 0 setzten 
			addr.sin_family=AF_INET;
			addr.sin_port=htons(12345); // wir verwenden mal port 12345
			addr.sin_addr.s_addr=inet_addr(IPAdresse); // zielrechner ist unser eigener
			rc=connect(s,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR));
			if(rc==SOCKET_ERROR)
			{
				//Fehler: connect gescheitert, fehler code: %d\n&quot;,WSAGetLastError()
				closesocket(s);
				status = 2;
			}
			else
			{
				//Verbunden mit 127.0.0.1..
				status = 1;
			}
		}
		int GiveStatus()
		{
			return status;
		}
		char *recieve()
		{
			char *buffer = new char[256];
			rc=recv(s,buffer,256,0);
			buffer[rc] = '\0';
			if(rc==0 || rc==SOCKET_ERROR)
				return &quot;&quot;;
			return buffer;
		}
		void sendData(char *strToSend)
		{
			rc=send(s,strToSend,strlen(strToSend),0);
		}
		void end()
		{
			closesocket(s);
			WSACleanup();
		}
	};
	class MakeSocketsServer
	{
	private:
		SOCKET acceptSocket;
		SOCKET connectedSocket[MAX_CLIENTS];
		long rc;
		int port;
		SOCKADDR_IN addr;
	public:
		MakeSocketsServer()
		{
			// Winsock starten
			rc=startWinsock();
			// Socket erstellen
		for(int i=0;i&lt;MAX_CLIENTS;i++) 
		  {
			connectedSocket[i]=INVALID_SOCKET;
		  }
		}
		void setPort(int portnum)
		{
			port = portnum;
		}
		int CreateSock(SOCKET x)
		{
			int ret = -1;
			for(int i=0;i&lt;MAX_CLIENTS;++i)
			{
				if(connectedSocket[i] == INVALID_SOCKET)
				{
					connectedSocket[i] = x;
					addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;-&gt;Neuer Socket erstellt auf Platz &quot;,itos(i)));
					ret = i;
					break;
				}
				if(i == MAX_CLIENTS-1)
				{
					PostQuitMessage(0);
				}
			}
			acceptSocket=socket(AF_INET,SOCK_STREAM,0);
			if(acceptSocket==INVALID_SOCKET)
			{
				closesocket(acceptSocket);
			}
			else
			{
				//socket erstellt
			}
			memset(&amp;addr,0,sizeof(SOCKADDR_IN));
			addr.sin_family=AF_INET;
			addr.sin_port=htons(port);
			addr.sin_addr.s_addr=INADDR_ANY;
			rc=bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN));
			if(rc==SOCKET_ERROR)
			{
				//Fehler: bind, fehler code: %d\n&quot;,WSAGetLastError()...
				closesocket(acceptSocket);
			}
			else
			{
				//Socket an port 12345 gebunden
			}
			return ret;
		}
		void listenS(int i)
		{
			rc=listen(acceptSocket,10);
			if(rc==SOCKET_ERROR)
			{
				//Fehler: listen, fehler code: %d\n&quot;,WSAGetLastError()
				closesocket(acceptSocket);
			}
			else
			{	
				//acceptSocket ist im listen Modus....
				addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;-&gt;Im Listenmodus(warte auf client...)&quot;);
			}
			connectedSocket[i]=accept(acceptSocket,NULL,NULL);
			if(connectedSocket[i]==INVALID_SOCKET)
			{
				//Fehler: accept, fehler code: %d\n&quot;,WSAGetLastError()...
				closesocket(acceptSocket);
			}
			else
			{
				addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;-&gt;Client Verbunden!&quot;);
///-------------------------------------------------
//Hier möchte ich, das jedesmal wenn ein client neu connected ein neuer thread erstellt wird, der auf den nächsten client wartet.
//wenn ich das weglasse, dann kann ich mit einem client connecten und daten austauschen...aber halt nur mit einem...
				HANDLE hAcceptThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RcvProcS, NULL, NULL, NULL);
//kann das problem sei, das die klasse immer nur ein listen verwalten kann?
//--------------------------------------------------
			}
		}
		int answer(int i)
		{
				char *buffer = new char[256];
				rc=recv(connectedSocket[i],buffer,256,0);
				buffer[rc] = '\0';
				if(rc!=0 &amp;&amp; rc!=SOCKET_ERROR)
				{
					int lineCode = getStrCode(buffer);
					char *lineStr = new char[strlen(buffer)-3];
					lineStr = getLwC(buffer);
					switch(lineCode)
					{
					case 0:
						addLine(GetDlgItem(dlgBox,IDC_SHOW),lineStr);
						break;
					case 1:
						addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;x changes name...&quot;);
						break;
					}
					delete [] buffer;
				}
				else
				{
					return 1;
				}
				return 0;
		}
		void sendData(char *strToSend, int i)
		{
			rc=send(connectedSocket[i],strToSend,strlen(strToSend),0);
		}
		void end()
		{
			for(int i=0;i&lt;MAX_CLIENTS;++i)
				closesocket(connectedSocket[i]);
			closesocket(acceptSocket);
			WSACleanup();
		}
		void endCon(int i)
		{
			closesocket(connectedSocket[i]);
		}
		bool isValid(int i)
		{
			if(connectedSocket[i] == INVALID_SOCKET)
				return FALSE;
			return TRUE;
		}
};
MakeSockets Sock;
MakeSocketsServer SockServer;
//Deklaration der Windows-Nachrichten-Prozedur 
///---------------------WIndow krams.......
		HANDLE hAcceptThread;
		switch (message) 
		{
			case WM_INITDIALOG:
				ShowWindow(hwnd, SW_SHOWNORMAL);
				dlgBox=hwnd;
				return TRUE;
			case WM_COMMAND: 
            	if(LOWORD(wParam) == IDOK)
				{	
					char *ip = new char[GetEditTextLength(GetDlgItem(hwnd,IDC_IPADDRESS))];
					ip = WindowText(GetDlgItem(hwnd,IDC_IPADDRESS));
					Sock.ConnectSock(ip);
					if(Sock.GiveStatus() == 1)
					{
						addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;Konnte zu &quot;,CombinChars(ip,&quot; verbinden&quot;)));
					}
					else if(Sock.GiveStatus() == 2)
					{
						addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;Konnte nicht zu &quot;,CombinChars(ip,&quot; verbinden&quot;)));
					}
					hAcceptThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RcvProc, NULL, NULL, NULL);
				}
				if(LOWORD(wParam) == ID_SEND)
				{
					char *buf = new char[GetEditTextLength(GetDlgItem(hwnd,IDC_TOSEND))-3];
					buf = WindowText(GetDlgItem(hwnd,IDC_TOSEND));
					Sock.sendData(CombinChars(&quot;001&quot;,buf));
					addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;[me]:&quot;,buf));
				}
				return TRUE;
			case WM_CLOSE:
				Sock.end();
				EndDialog(hwnd,0);
		}  
		return FALSE;
	}
	LRESULT CALLBACK MakeProcS (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
	{
		HANDLE hAcceptThread;
		switch (message) 
		{
			case WM_INITDIALOG:
				dlgBox=hwnd;
				return TRUE;
			case WM_COMMAND: 
            	if(LOWORD(wParam) == IDOK)
				{	
					char *port = new char[GetEditTextLength(GetDlgItem(hwnd,IDC_PORT))];
					port = WindowText(GetDlgItem(hwnd,IDC_PORT));
					DWORD  idAcceptThread;
					SockServer.setPort(atof(port));
					hAcceptThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)RcvProcS, NULL, NULL, &amp;idAcceptThread);
				}
				if(LOWORD(wParam) == ID_SEND)
				{
					char *buf = new char[GetEditTextLength(GetDlgItem(hwnd,IDC_TOSEND))];
					buf = WindowText(GetDlgItem(hwnd,IDC_TOSEND));
					for(int x=0;x&lt;MAX_CLIENTS;++x)
					{
						if(SockServer.isValid(x))
							SockServer.sendData(buf,x);
					}
					addLine(GetDlgItem(dlgBox,IDC_SHOW),CombinChars(&quot;[me]:&quot;,buf));
				}
				return TRUE;
			case WM_CLOSE:
				SockServer.end();
				EndDialog(hwnd,0);
		}  
		return FALSE;
	}
	LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
	{ 
	switch (message) 
	{ 
	case WM_CREATE:
		if(LOWORD(wParam) == 0) 
		{

		}
		return 0 ;
	case WM_COMMAND:
		if(LOWORD(wParam) == ID_CONNECT)
		{
			DialogBox(hInst,(LPCTSTR)IDD_DIALOG, hwnd, (DLGPROC)MakeProc);
		}
		if(LOWORD(wParam) == ID_SERVER_ERSTELLEN)
		{
			DialogBox(hInst,(LPCTSTR)IDD_DIALOGS, hwnd, (DLGPROC)MakeProcS);
		}
		return 0;
	case WM_SIZE:
		return 0;
	case WM_CLOSE:
		DestroyWindow(hwnd);
	case WM_DESTROY:
		  PostQuitMessage (0);
		  return 0;
	}

return DefWindowProc (hwnd, message, wParam, lParam); 
} 

unsigned long RcvProc()
{
	while(1)
	{
		char *tmp = new char[256];
		tmp = Sock.recieve();
		if(tmp != &quot;&quot;)
			addLine(GetDlgItem(dlgBox,IDC_SHOW),tmp);
		else
		{
			addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;Connection Error&quot;);
			Sock.end();
			return 0;
		}
	}
return 0; 
}
unsigned long RcvProcS()
{
	SOCKET theSocket;
	int sockNum;
	sockNum = SockServer.CreateSock(theSocket);
	SockServer.listenS(sockNum);
	int x = 0;
	while(x==0)
	{
		x = SockServer.answer(sockNum);
	}
	SockServer.endCon(sockNum);
	addLine(GetDlgItem(dlgBox,IDC_SHOW),&quot;Client verloren...&quot;);
	return 0;

}
</code></pre>
<p>edit wer n tut hat zu sockets in winAPI mit threads..bitte linken <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/556200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/556200</guid><dc:creator><![CDATA[pixartist]]></dc:creator><pubDate>Thu, 08 Jul 2004 15:36:12 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Fri, 09 Jul 2004 10:11:41 GMT]]></title><description><![CDATA[<p>bitte helft mir <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>
]]></description><link>https://www.c-plusplus.net/forum/post/556705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/556705</guid><dc:creator><![CDATA[pixartist]]></dc:creator><pubDate>Fri, 09 Jul 2004 10:11:41 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Fri, 09 Jul 2004 11:34:27 GMT]]></title><description><![CDATA[<p><a href="http://www.gamedev.net/reference/articles/article1059.asp" rel="nofollow">http://www.gamedev.net/reference/articles/article1059.asp</a><br />
<a href="http://www.gamedev.net/reference/articles/article1494.asp" rel="nofollow">http://www.gamedev.net/reference/articles/article1494.asp</a></p>
<p>fallen mir grad ein, wenn ich noch welche find, sag ichs...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/556765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/556765</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Fri, 09 Jul 2004 11:34:27 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Fri, 09 Jul 2004 12:05:34 GMT]]></title><description><![CDATA[<p>Deine Klasse ist Murks, sprich nutzlos. Sie ist so komplex dass man ein paar kleinigkeiten nciht mehr tun muss aber doch so klein dass man immer noch viel selber machen muss. Am Ende ist es so, dass der Text den man eingibt um die Methoden aufzurufen nciht viel kürzeer ist als gleich WINAPI ungekapselt zu nutzen. Fazit: Murks.</p>
<p>Zu der Sache mit den Threads:</p>
<p>1. empfehle ich dir select()--&gt; ist viel eleganter / ressourcenshconender / einfacher..</p>
<p>2.Wenn du Threads liebst und nicht loslassen kannst:<br />
Du solltest mit ner map arbeiten, d.h. jedem clientsocket ein threadhandle zuordnen und immer wenn der client diesconnectet den thread auslaufen lassen.</p>
<p>Mfg. Tolga</p>
]]></description><link>https://www.c-plusplus.net/forum/post/556800</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/556800</guid><dc:creator><![CDATA[Tolga]]></dc:creator><pubDate>Fri, 09 Jul 2004 12:05:34 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Fri, 09 Jul 2004 14:55:17 GMT]]></title><description><![CDATA[<p>ah endlich...antworten <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="🙂"
    /><br />
dankeschön</p>
<p>edit:wobei ich immernoch nicht weiss, wo mein fehler liegt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/556902</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/556902</guid><dc:creator><![CDATA[pixartist]]></dc:creator><pubDate>Fri, 09 Jul 2004 14:55:17 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Fri, 09 Jul 2004 19:29:07 GMT]]></title><description><![CDATA[<p>habe deinen Quelltext nicht wirklich durchgeschaut...aber mal ne Frage:<br />
- Wie machst du das mit dem Port? hast du für jeden neuen ServerSocket einen Neuten Port? Sonst kannst du meinen wissens nicht mit Mehreren Clients auf ServerSockets mit dem Gleichen Ports zugreifen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/557120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/557120</guid><dc:creator><![CDATA[scheissPi-ber**]]></dc:creator><pubDate>Fri, 09 Jul 2004 19:29:07 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Fri, 09 Jul 2004 19:44:36 GMT]]></title><description><![CDATA[<p>Es ist möglich mehrere Sockets an einen Port zu binden!<br />
Mit SetSockOpt().</p>
<p>Mfg. Tolga</p>
]]></description><link>https://www.c-plusplus.net/forum/post/557126</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/557126</guid><dc:creator><![CDATA[Tolga]]></dc:creator><pubDate>Fri, 09 Jul 2004 19:44:36 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Fri, 09 Jul 2004 20:39:38 GMT]]></title><description><![CDATA[<p>oO ach normalerweise kann nur ein socket an einen port?? -.-<br />
ich werds mal mit select probiern....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/557148</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/557148</guid><dc:creator><![CDATA[pixartist]]></dc:creator><pubDate>Fri, 09 Jul 2004 20:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Fri, 09 Jul 2004 21:20:33 GMT]]></title><description><![CDATA[<p>Mal ne Frage,</p>
<p>habe noch nicht viel Ahnung von dem Thema, versuche mich gerade mit Indy<br />
gibt es da eine einfache Möglichkeit einen Text an einen anderen Rechner zu<br />
senden von dem die IP bekannt ist?<br />
Wenn der der andere Rechner meine IP erkennt soll er den Text auswerten.</p>
<p>Was ist in diesem Zusammenhang ein Thread ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/557183</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/557183</guid><dc:creator><![CDATA[hermes]]></dc:creator><pubDate>Fri, 09 Jul 2004 21:20:33 GMT</pubDate></item><item><title><![CDATA[Reply to socket problem -&amp;gt; mehrere clients mit threads on Sat, 10 Jul 2004 14:26:58 GMT]]></title><description><![CDATA[<p>hmm ich habe das mal so gelöst:</p>
<p>zwei Ports: port1, port2</p>
<pre><code>Server -------------------------| Client ------------------------
________________________________|________________________________
- ServerSocket(port1) erstellen |
mit tread welcher auf neue      |
verbindungen wartet.            |
                                | - Client(port1) mit Server verbinden
- sobald Verbunden port2 senden | - sobald Verbunden port2 empfangen
                                | einen ServerSocket(port2) erstellen
- Client[i] (port2) mit         |
ServerSocket verbinden          |

--&gt; Kommunikation nun über den port2 hergestellt

--&gt; thread wartet nun wieder auf neue verbindungen welche dann einfach z.B über den Client[i+1] hergestellt wird
</code></pre>
<p>drausgekommen....tja egal bei mir hat es so wunderbar geklappt!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/557520</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/557520</guid><dc:creator><![CDATA[scheissPi-ber**]]></dc:creator><pubDate>Sat, 10 Jul 2004 14:26:58 GMT</pubDate></item></channel></rss>