<?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[Hilfe beim Client&#x2F;Server...]]></title><description><![CDATA[<p>Hallo Leute, ich habe ein Client und Server. Der Client übergibt dem Server ein Befehl der dann eine bestimmte *.exe startet. Diese Ausgabe des Befehls wird vom Server an den Client umgeleitet. Das Problem ist, dass die Ausgabe vom Server zu spät beim Client ankommt, d.h. wenn ich ein Befehl eingabe und Enter drücke, dann kommt nicht sofort die Ausgabe beim Client an, sondern nach einem zweiten Enter.<br />
Könntet Ihr euch das bitte anschaun.</p>
<p>Client:</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt; 
#include &lt;stdio.h&gt; 
#include &lt;windows.h&gt; 
#include &lt;winsock.h&gt; 
#include &lt;conio.h&gt; 
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;cstdio&gt; 
#include &lt;vector&gt;
#include &quot;format.h&quot;

using namespace std;

#pragma comment(lib,&quot;wsock32.lib&quot;)
#pragma comment(lib,&quot;advapi32.lib&quot;)

// Startet Winsock und gibt einige Infos zur Version aus 
// Starts winsock and dumps some infos about the version 
int startWinsock() 
{ 
   int rc; 
   WSADATA wsaData; 
   rc=WSAStartup(MAKEWORD(2,0),&amp;wsaData); 

   if(rc==SOCKET_ERROR) 
   { 
      printf(&quot;Error, exiting!\n&quot;); 
      return rc; 
   }  
   //printf(&quot;System Status: %s\n&quot;,wsaData.szSystemStatus); 
   return 0; 
} 

// Sucht eine IP anhand eines Strings, der entweder die IP als String 
// oder einen Hostname enthalten kann 
long getAddrFromString(char* hostnameOrIp, SOCKADDR_IN* addr) 
{ 
   long rc; 
   unsigned long ip; 

   HOSTENT* he; 

   if(hostnameOrIp==NULL || addr==NULL) 
      return SOCKET_ERROR; 
   ip=inet_addr(hostnameOrIp); 

   if(ip!=INADDR_NONE)
   { 
      addr-&gt;sin_addr.s_addr=ip; 
      return 0; 
   } 
   else 
   { 
      he=gethostbyname(hostnameOrIp); 
      if(he==NULL) 
      { 
         return SOCKET_ERROR; 
      } 
      else 
      { 
         memcpy(&amp;(addr-&gt;sin_addr),he-&gt;h_addr_list[0],4); 
      } 
      return 0; 
   } 
} 

int main(int argc, char* argv[]) 
{    
    if(argc &gt; 2)
    {
        char* HOST = argv[1];
        int PORT = atoi(argv[2]);

        SOCKET s; 
        SOCKADDR_IN addr; 
        char c; 
        char buf[1024]; 
        char inpBuf[1024]; 
        int inpBufPos=0; 
        fd_set fdSetRead; 
        TIMEVAL timeout; 
        int rc; 

        // start winsock 
        rc=startWinsock(); 
        if(rc==SOCKET_ERROR) 
        return 1; 

        // addr vorbereiten, hostname auflösen 
        // prepare addr, resolve hostname 
        memset(&amp;addr,0,sizeof(SOCKADDR_IN)); 
        addr.sin_family=AF_INET; 
        addr.sin_port=htons(PORT); 
        rc=getAddrFromString(HOST, &amp;addr); 
        if(rc==SOCKET_ERROR) 
        { 
            printf(&quot;Error: Cannot resolve Host %s\n&quot;, HOST); 
            return 1; 
        } 

        // socket erstellen 
        // create socket 
        s=socket(PF_INET,SOCK_STREAM,0); 
        if(s==INVALID_SOCKET) 
        { 
            printf(&quot;Error, cannot create socket: %d\n&quot;,WSAGetLastError()); 
            return 1; 
        } 

        // verbinden.. 
        // connect.. 
        printf(&quot;Connecting...\n&quot;); 
        rc=connect(s,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR)); 
        if(rc==SOCKET_ERROR) 
        { 
            printf(&quot;Error: connect failed: %d\n&quot;,WSAGetLastError()); 
            return 1; 
        }

        cout &lt;&lt; endl;

        string str; //Eingabe String

        do
        {

            cout &lt;&lt; &quot;Eingabe:&gt;&quot;;

            getline(cin, str);

            if(str == &quot;exit&quot;)
            {
                closesocket(s); 
                WSACleanup(); 
                return 0;
            }

            else if(str == &quot;close&quot;)
            {
                rc=send(s,str.c_str(),strlen(str.c_str()),0); 
                if(rc==SOCKET_ERROR)
                {
                    printf(&quot;Error: Sending to Server failed: %d\n&quot;,WSAGetLastError()); 
                } 
                closesocket(s); 
                WSACleanup(); 
                return 0;
            }
            //Sende Befehl...
            rc=send(s,str.c_str(),strlen(str.c_str()),0); 
            if(rc==SOCKET_ERROR)
            {
                printf(&quot;Error: Sending to Server failed: %d\n&quot;,WSAGetLastError()); 
            } 

            // fd_set und timeout vorbereiten 
            FD_ZERO(&amp;fdSetRead); 
            FD_SET(s,&amp;fdSetRead); 
            timeout.tv_sec=0; 
            timeout.tv_usec=0; 

            // prüfen ob ein socket bereit ist, da timeout=0 kehrt die funktion 
            // sofort wieder zurück nach dem aufruf. 
            // achtung: das timeout auf 0 setzen oder als paremeter NULL mitgeben 
            // ist NICHT das gleiche. auf 0 gesetzt kehrt sofort zurück, während NULL blockt. 
            while((rc=select(0,&amp;fdSetRead,NULL,NULL,&amp;timeout))&gt;0) 
            { 
                rc=recv(s,buf,1024,0); 
                // server hat die verbindung beendet ? 
                if(rc==0) 
                { 
                    printf(&quot;Server closed connection!\n&quot;); 
                    return 1; 
                // fehler: beenden! 
                } 
                else if(rc==SOCKET_ERROR) 
                { 
                    printf(&quot;Error: recv failed: %d\n&quot;,WSAGetLastError()); 
                    return 1; 
                } 
                // empfangene daten ausgeben 
                buf[rc]='\0'; 
                cout &lt;&lt; buf &lt;&lt; endl;
            } 

        }while(rc!=SOCKET_ERROR);//Ende do-while

        // aufräumen 
        // cleanup.. 
        closesocket(s); 
        WSACleanup(); 
        cout &lt;&lt; &quot;Client shutdown, press any key to exit&quot; &lt;&lt; endl;
        getch(); 

       }
       else    
       {
           cout &lt;&lt; &quot;Client HOST PORT&quot; &lt;&lt; endl;
       }
       return 0; 

}
</code></pre>
<p>Server:</p>
<pre><code>// max. Anzahl Clients 
// Max. number of clients 
#define MAX_CLIENTS 20

// Der Standartwert für FD_SETSIZE ist 64, dieser kann aber verändert 
// werden indem man FD_SETSIZE auf einen anderen Wert setzt bevor man 
// winsock2.h includiert. 
// FD_SETSIZE auf die max. Anzahl Clients setzten 
#define FD_SETSIZE   MAX_CLIENTS 

// includes... 
#include &lt;stdlib.h&gt; 
#include &lt;stdio.h&gt; 
#include &lt;windows.h&gt; 
#include &lt;winsock.h&gt; 
#include &lt;conio.h&gt; 
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &quot;convert.h&quot;
#include &quot;registry.h&quot;

#pragma comment(lib, &quot;wsock32.lib&quot;)
#pragma comment(lib, &quot;advapi32.lib&quot;)
#pragma comment(lib,&quot;user32.lib&quot;)

using namespace std;

// Stellt eine Verbindung mit einem Client dar 
// Represents a connection with a Client 
struct Connection 
{ 
   Connection() 
   { 
      used=false; 
      socket=INVALID_SOCKET; 
   } 
   void set(SOCKET s, SOCKADDR_IN addr) 
   { 
      this-&gt;socket=s; 
      this-&gt;addr=addr; 
      this-&gt;used=true; 
   } 
   void erase() 
   { 
      this-&gt;used=false; 
      this-&gt;socket=INVALID_SOCKET; 
   } 
   bool used;   // connection benutzt ? / connection slot used ? 
   SOCKET socket; // socket 
   SOCKADDR_IN addr; // client addr 
}; 

// clients 
Connection clients[MAX_CLIENTS]; 

// Sucht den nächsten freien Platz im clients Array 
// -1 = kein platz frei 
// Searches the next free slot in the clients array 
// -1 = no free slot 
int getFreeClientSlot() 
{ 
   for(int i=0;i&lt;MAX_CLIENTS;i++) 
   { 
      if(clients[i].used==false) 
         return i; 
   } 
   return -1; 
} 

// Startet Winsock und gibt einige Infos zur Version aus 
// Starts winsock and dumps some infos about the version 
int startWinsock() 
{ 
   int rc; 
   WSADATA wsaData; 
   rc=WSAStartup(MAKEWORD(2,0),&amp;wsaData); 

   if(rc==SOCKET_ERROR) { 
      printf(&quot;Error, exiting!\n&quot;); 
      return rc; 
   }   
   printf(&quot;System Status: %s\n&quot;,wsaData.szSystemStatus); 
   return 0; 
} 

#define MAX_LINE_LENGTH 1024

BOOL ProcessCommandLine(char * pcCommandLine, SOCKET s)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    SECURITY_ATTRIBUTES sa;
    HANDLE hReadPipe, hWritePipe;
    DWORD dwWaitResult = WAIT_TIMEOUT, dwBytesRead, dwExitCode, dwSizeLow, dwSizeHigh, dwError;
    char cReadLine[MAX_LINE_LENGTH];
    BOOL bDoRead = TRUE, bOK = TRUE;
    MSG AppMsg;

    ZeroMemory(&amp;si, sizeof(si));
    si.cb = sizeof(si);

    //Pipes erzeugen
    sa.nLength=sizeof(sa);
    sa.bInheritHandle=TRUE;
    sa.lpSecurityDescriptor=NULL;
    bOK = CreatePipe(&amp;hReadPipe, &amp;hWritePipe, &amp;sa, 1048576);
    if(!bOK)
    {
        //FEHLER
        dwError = GetLastError();
        bOK = FALSE;
        goto PROCESS_END_NOPIPE;
    }

    //Pipes eintragen
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
    si.hStdOutput = hWritePipe;                        //Schreib-Ende der Pipe an Prozess übergeben
    si.hStdError = hWritePipe;                        //Schreib-Ende der Pipe an Prozess übergeben
    si.wShowWindow = SW_SHOWMINNOACTIVE;

    //Prozess starten
    bOK = CreateProcess(NULL,
                        pcCommandLine,
                        NULL,
                        NULL,
                        TRUE,
                        NORMAL_PRIORITY_CLASS,
                        NULL,
                        NULL,
                        &amp;si,
                        &amp;pi);

    if(!bOK)
    {
        //FEHLER
        dwError = GetLastError();
        goto PROCESS_END_NOPROC;
    }

    //Auf Ende warten und Messages lesen
    while(dwWaitResult != WAIT_OBJECT_0)
    {
        dwWaitResult = WaitForSingleObject(pi.hProcess, 10);
        while(dwSizeLow = GetFileSize(hReadPipe, &amp;dwSizeHigh))
        {
            ZeroMemory(cReadLine, MAX_LINE_LENGTH);
            //Aus dem Leseende der Pipe die Progzessausgaben lesen
            if(bDoRead = ReadFile(hReadPipe, cReadLine, MAX_LINE_LENGTH - 1, &amp;dwBytesRead, NULL))
            {
                if(dwBytesRead)
                {
                    //**** hier Programmausgabe verarbeiten (z.B. send) *******
                    send(s, cReadLine, strlen(cReadLine), 0);
                }
            }
            else
            {
                bOK = FALSE;
                dwError = GetLastError();
            }
        }
        //Applikations-Messagequeue verarbeiten
        if(PeekMessage(&amp;AppMsg, 0, 0, 0, PM_NOREMOVE))
        {
            GetMessage(&amp;AppMsg, 0, 0, 0);
            TranslateMessage(&amp;AppMsg);
            DispatchMessage(&amp;AppMsg);
        }
    }

    if(bOK)
    {
        bOK = GetExitCodeProcess(pi.hProcess, &amp;dwExitCode);
        if(bOK)
        {
            if(dwExitCode != 0)
            {
                //Prozess kehrt mit Ergebnis != 0 zurück
                bOK = FALSE;
            }
        }
        else
        {
            //FEHLER im GetExitCodeProcess
            dwError = GetLastError();
            bOK = FALSE;
        }
    }

    //Close handles
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);

PROCESS_END_NOPROC:
    CloseHandle(hWritePipe);
    CloseHandle(hReadPipe);

PROCESS_END_NOPIPE:
    return bOK;
}

int main(int argc, char* argv[]) 
{ 
    if(argc &gt; 1)
    {
        //Startet auf dem übergebenem PORT
        int PORT = atoi(argv[1]);

       // SOCKET welcher neue Verbindungen annimmt 
       // SOCKET which accepts new connections 
       SOCKET acceptSocket; 
       SOCKADDR_IN addr; 
       int rc,addrsize=sizeof(SOCKADDR_IN); 
       unsigned int i,j; 
       // fd_set 
       fd_set fdSetRead; 
       // timout für select() / timeout for select() 
       timeval selectTimeout; 
       // temporär benutz für neue verbindungen 
       // temporary used for new connections 
       Connection newConnection; 
       // buffer 
       char buf[1024]; 

       // clients array leeren / clear clients array 
       memset(clients,0x0,sizeof(Connection)*MAX_CLIENTS); 

       // start winsock 
       rc=startWinsock(); 
       if(rc==SOCKET_ERROR) 
          return 1; 

       // socket erstellen / create socket 
       acceptSocket=socket(PF_INET,SOCK_STREAM,0); 
       if(acceptSocket==INVALID_SOCKET) 
       { 
          printf(&quot;Error, cannot create socket: %d\n&quot;,WSAGetLastError()); 
          return 1; 
       } 

       // sockt an port 1234 binden / bind socket to port 1234 
       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) 
       { 
          printf(&quot;Error, bind() failed: %d\n&quot;,WSAGetLastError()); 
          return 1; 
       } 

       // auf verbindungen warten / listen for connections 
       rc=listen(acceptSocket,10); 
       if(rc==SOCKET_ERROR) 
       { 
          printf(&quot;Error,listen() failed: %d\n&quot;,WSAGetLastError()); 
          return 1; 
       } 

       // The parameter readfds identifies the sockets that are to be checked for readability. 
       // If the socket is currently in the listen state, it will be marked as readable if an 
       // incoming connection request has been received such that an accept is guaranteed to 
       // complete without blocking. 

       while(1) 
       { 

          // fd_set leeren / clear fd_set 
          FD_ZERO(&amp;fdSetRead); 

          // den socket welcher verbindungen annimmt hinzufügen 
          // add the SOCKET which accepts new connections 

          FD_SET(acceptSocket,&amp;fdSetRead); 
          // alle clients hinzufügen 
          // add all clients 
          for(i=0;i&lt;MAX_CLIENTS;i++) 
          { 
             if(clients[i].used) 
                FD_SET(clients[i].socket,&amp;fdSetRead); 
          } 

          // warten bis irgend ein socket bereit ist, wenn timout NULL ist kehrt select() 
          // erst zurück wenn ein socket bereit ist, select() blockt also in diesem falle 
          // wait until any socket is ready (timeout = NULL, block until one socket is ready) 
          rc=select(0,&amp;fdSetRead,NULL,NULL,NULL); 

          // abbrechen bei einem fehler 
          // break on error 
          if(rc&lt;1) 
             break; 

          printf(&quot;select() returned %d ready sockets\n&quot;,rc); 

          for(i=0;i&lt;fdSetRead.fd_count;i++) 
          { 

             // acceptSocket ? 
             if(fdSetRead.fd_array[i]==acceptSocket) 
             { 
                // verbindung annehmen / accept new connection 
                newConnection.socket=accept(acceptSocket,(SOCKADDR*)&amp;newConnection.addr,&amp;addrsize); 
                rc=getFreeClientSlot(); 
                if(rc==-1) 
                { 
                   printf(&quot;Cannot accept new clients\n&quot;); 
                   continue; 
                } 
                // zu den clients hinzufügen 
                // add to clients 
                clients[rc]=newConnection; 
                clients[rc].used=true; 
                printf(&quot;New Client accepted from %s\n&quot;,inet_ntoa(newConnection.addr.sin_addr)); 
                continue; 
             } 

             // ein client ? 
             // a client ? 
             for(j=0;j&lt;MAX_CLIENTS;j++) 
             { 
                if(!clients[j].used) 
                   continue; 

                if(clients[j].socket==fdSetRead.fd_array[i]) 
                { 
                   rc=recv(clients[j].socket,buf,1023,0); 
                   buf[rc]='\0'; 
                   // rc==0 =&gt; client hat die verbindung beendet 
                   if(rc==0) { 
                      printf(&quot;Client %d (%s): closed connection\n&quot;,j,inet_ntoa(clients[j].addr.sin_addr)); 
                      closesocket(clients[j].socket); 
                      clients[j].erase(); 
                      continue; 
                   // rc==SOCKET_ERROR =&gt; fehler, verbindung beenden! 
                   } 
                   else if(rc==SOCKET_ERROR) 
                   { 
                      printf(&quot;Client %d (%s): Error %d\n&quot;,j,inet_ntoa(clients[j].addr.sin_addr),WSAGetLastError()); 
                      printf(&quot;Client %d (%s): Server aborts connection\n&quot;,j,inet_ntoa(clients[j].addr.sin_addr)); 
                      closesocket(clients[j].socket); 
                      clients[j].erase(); 
                      continue; 
                   // daten empfangen und an alle clients senden 
                   } 
                   else 
                   { 
                       printf(&quot;Client %d (%s): Befehl: '%s' \n&quot;,j,inet_ntoa(clients[j].addr.sin_addr),buf); 
                      //sendToAllClients(buf); 

                      string command = buf;
                      if(command.find(' ') != string::npos)
                      {                          
                          int pos = command.find(' ');   
                          int lang = command.length();
                            string task = command.substr(0,pos);
                          string para = command.substr(pos+1,lang);

                          string str;
                          str += '&quot;';
                          str += reg.xmd_GetValue(&quot;bin&quot;);
                          str += &quot;\\&quot;;
                          str += task;
                          str += &quot;.exe&quot;;
                          str += '&quot;';
                          str += &quot; &quot; + para;

                          cout &lt;&lt; &quot;Erfolgreich: &quot; &lt;&lt; ProcessCommandLine(cvt.StringToChar(str), clients[j].socket) &lt;&lt; endl;
                      }

                      else
                      {                            
                         if(command == &quot;close&quot;)                        
                         {
                             //rc=send(clients[i].socket,msg,strlen(msg),0); 
                             //  rc=send(clients[j].socket,task.c_str(),strlen(task.c_str()),0); 
                             closesocket(acceptSocket); 
                             WSACleanup();
                         }                         
                         cout &lt;&lt; &quot;Erfolgreich: &quot; &lt;&lt; ProcessCommandLine(cvt.StringToChar(command), clients[j].socket) &lt;&lt; endl;
                      }          

                   } 
                } 
             } 
          }

          cout &lt;&lt; &quot;-----------------------------------&quot; &lt;&lt; endl;
       }//Ende while

       // aufräumen 
       closesocket(acceptSocket); 
       WSACleanup();        
    }
    else 
    {
        cout &lt;&lt; &quot;server PORT&quot; &lt;&lt; endl;
    }

    return 0;   
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/159931/hilfe-beim-client-server</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Jul 2026 07:00:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/159931.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Sep 2006 09:29:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Wed, 20 Sep 2006 09:29:44 GMT]]></title><description><![CDATA[<p>Hallo Leute, ich habe ein Client und Server. Der Client übergibt dem Server ein Befehl der dann eine bestimmte *.exe startet. Diese Ausgabe des Befehls wird vom Server an den Client umgeleitet. Das Problem ist, dass die Ausgabe vom Server zu spät beim Client ankommt, d.h. wenn ich ein Befehl eingabe und Enter drücke, dann kommt nicht sofort die Ausgabe beim Client an, sondern nach einem zweiten Enter.<br />
Könntet Ihr euch das bitte anschaun.</p>
<p>Client:</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt; 
#include &lt;stdio.h&gt; 
#include &lt;windows.h&gt; 
#include &lt;winsock.h&gt; 
#include &lt;conio.h&gt; 
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;cstdio&gt; 
#include &lt;vector&gt;
#include &quot;format.h&quot;

using namespace std;

#pragma comment(lib,&quot;wsock32.lib&quot;)
#pragma comment(lib,&quot;advapi32.lib&quot;)

// Startet Winsock und gibt einige Infos zur Version aus 
// Starts winsock and dumps some infos about the version 
int startWinsock() 
{ 
   int rc; 
   WSADATA wsaData; 
   rc=WSAStartup(MAKEWORD(2,0),&amp;wsaData); 

   if(rc==SOCKET_ERROR) 
   { 
      printf(&quot;Error, exiting!\n&quot;); 
      return rc; 
   }  
   //printf(&quot;System Status: %s\n&quot;,wsaData.szSystemStatus); 
   return 0; 
} 

// Sucht eine IP anhand eines Strings, der entweder die IP als String 
// oder einen Hostname enthalten kann 
long getAddrFromString(char* hostnameOrIp, SOCKADDR_IN* addr) 
{ 
   long rc; 
   unsigned long ip; 

   HOSTENT* he; 

   if(hostnameOrIp==NULL || addr==NULL) 
      return SOCKET_ERROR; 
   ip=inet_addr(hostnameOrIp); 

   if(ip!=INADDR_NONE)
   { 
      addr-&gt;sin_addr.s_addr=ip; 
      return 0; 
   } 
   else 
   { 
      he=gethostbyname(hostnameOrIp); 
      if(he==NULL) 
      { 
         return SOCKET_ERROR; 
      } 
      else 
      { 
         memcpy(&amp;(addr-&gt;sin_addr),he-&gt;h_addr_list[0],4); 
      } 
      return 0; 
   } 
} 

int main(int argc, char* argv[]) 
{    
    if(argc &gt; 2)
    {
        char* HOST = argv[1];
        int PORT = atoi(argv[2]);

        SOCKET s; 
        SOCKADDR_IN addr; 
        char c; 
        char buf[1024]; 
        char inpBuf[1024]; 
        int inpBufPos=0; 
        fd_set fdSetRead; 
        TIMEVAL timeout; 
        int rc; 

        // start winsock 
        rc=startWinsock(); 
        if(rc==SOCKET_ERROR) 
        return 1; 

        // addr vorbereiten, hostname auflösen 
        // prepare addr, resolve hostname 
        memset(&amp;addr,0,sizeof(SOCKADDR_IN)); 
        addr.sin_family=AF_INET; 
        addr.sin_port=htons(PORT); 
        rc=getAddrFromString(HOST, &amp;addr); 
        if(rc==SOCKET_ERROR) 
        { 
            printf(&quot;Error: Cannot resolve Host %s\n&quot;, HOST); 
            return 1; 
        } 

        // socket erstellen 
        // create socket 
        s=socket(PF_INET,SOCK_STREAM,0); 
        if(s==INVALID_SOCKET) 
        { 
            printf(&quot;Error, cannot create socket: %d\n&quot;,WSAGetLastError()); 
            return 1; 
        } 

        // verbinden.. 
        // connect.. 
        printf(&quot;Connecting...\n&quot;); 
        rc=connect(s,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR)); 
        if(rc==SOCKET_ERROR) 
        { 
            printf(&quot;Error: connect failed: %d\n&quot;,WSAGetLastError()); 
            return 1; 
        }

        cout &lt;&lt; endl;

        string str; //Eingabe String

        do
        {

            cout &lt;&lt; &quot;Eingabe:&gt;&quot;;

            getline(cin, str);

            if(str == &quot;exit&quot;)
            {
                closesocket(s); 
                WSACleanup(); 
                return 0;
            }

            else if(str == &quot;close&quot;)
            {
                rc=send(s,str.c_str(),strlen(str.c_str()),0); 
                if(rc==SOCKET_ERROR)
                {
                    printf(&quot;Error: Sending to Server failed: %d\n&quot;,WSAGetLastError()); 
                } 
                closesocket(s); 
                WSACleanup(); 
                return 0;
            }
            //Sende Befehl...
            rc=send(s,str.c_str(),strlen(str.c_str()),0); 
            if(rc==SOCKET_ERROR)
            {
                printf(&quot;Error: Sending to Server failed: %d\n&quot;,WSAGetLastError()); 
            } 

            // fd_set und timeout vorbereiten 
            FD_ZERO(&amp;fdSetRead); 
            FD_SET(s,&amp;fdSetRead); 
            timeout.tv_sec=0; 
            timeout.tv_usec=0; 

            // prüfen ob ein socket bereit ist, da timeout=0 kehrt die funktion 
            // sofort wieder zurück nach dem aufruf. 
            // achtung: das timeout auf 0 setzen oder als paremeter NULL mitgeben 
            // ist NICHT das gleiche. auf 0 gesetzt kehrt sofort zurück, während NULL blockt. 
            while((rc=select(0,&amp;fdSetRead,NULL,NULL,&amp;timeout))&gt;0) 
            { 
                rc=recv(s,buf,1024,0); 
                // server hat die verbindung beendet ? 
                if(rc==0) 
                { 
                    printf(&quot;Server closed connection!\n&quot;); 
                    return 1; 
                // fehler: beenden! 
                } 
                else if(rc==SOCKET_ERROR) 
                { 
                    printf(&quot;Error: recv failed: %d\n&quot;,WSAGetLastError()); 
                    return 1; 
                } 
                // empfangene daten ausgeben 
                buf[rc]='\0'; 
                cout &lt;&lt; buf &lt;&lt; endl;
            } 

        }while(rc!=SOCKET_ERROR);//Ende do-while

        // aufräumen 
        // cleanup.. 
        closesocket(s); 
        WSACleanup(); 
        cout &lt;&lt; &quot;Client shutdown, press any key to exit&quot; &lt;&lt; endl;
        getch(); 

       }
       else    
       {
           cout &lt;&lt; &quot;Client HOST PORT&quot; &lt;&lt; endl;
       }
       return 0; 

}
</code></pre>
<p>Server:</p>
<pre><code>// max. Anzahl Clients 
// Max. number of clients 
#define MAX_CLIENTS 20

// Der Standartwert für FD_SETSIZE ist 64, dieser kann aber verändert 
// werden indem man FD_SETSIZE auf einen anderen Wert setzt bevor man 
// winsock2.h includiert. 
// FD_SETSIZE auf die max. Anzahl Clients setzten 
#define FD_SETSIZE   MAX_CLIENTS 

// includes... 
#include &lt;stdlib.h&gt; 
#include &lt;stdio.h&gt; 
#include &lt;windows.h&gt; 
#include &lt;winsock.h&gt; 
#include &lt;conio.h&gt; 
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &quot;convert.h&quot;
#include &quot;registry.h&quot;

#pragma comment(lib, &quot;wsock32.lib&quot;)
#pragma comment(lib, &quot;advapi32.lib&quot;)
#pragma comment(lib,&quot;user32.lib&quot;)

using namespace std;

// Stellt eine Verbindung mit einem Client dar 
// Represents a connection with a Client 
struct Connection 
{ 
   Connection() 
   { 
      used=false; 
      socket=INVALID_SOCKET; 
   } 
   void set(SOCKET s, SOCKADDR_IN addr) 
   { 
      this-&gt;socket=s; 
      this-&gt;addr=addr; 
      this-&gt;used=true; 
   } 
   void erase() 
   { 
      this-&gt;used=false; 
      this-&gt;socket=INVALID_SOCKET; 
   } 
   bool used;   // connection benutzt ? / connection slot used ? 
   SOCKET socket; // socket 
   SOCKADDR_IN addr; // client addr 
}; 

// clients 
Connection clients[MAX_CLIENTS]; 

// Sucht den nächsten freien Platz im clients Array 
// -1 = kein platz frei 
// Searches the next free slot in the clients array 
// -1 = no free slot 
int getFreeClientSlot() 
{ 
   for(int i=0;i&lt;MAX_CLIENTS;i++) 
   { 
      if(clients[i].used==false) 
         return i; 
   } 
   return -1; 
} 

// Startet Winsock und gibt einige Infos zur Version aus 
// Starts winsock and dumps some infos about the version 
int startWinsock() 
{ 
   int rc; 
   WSADATA wsaData; 
   rc=WSAStartup(MAKEWORD(2,0),&amp;wsaData); 

   if(rc==SOCKET_ERROR) { 
      printf(&quot;Error, exiting!\n&quot;); 
      return rc; 
   }   
   printf(&quot;System Status: %s\n&quot;,wsaData.szSystemStatus); 
   return 0; 
} 

#define MAX_LINE_LENGTH 1024

BOOL ProcessCommandLine(char * pcCommandLine, SOCKET s)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    SECURITY_ATTRIBUTES sa;
    HANDLE hReadPipe, hWritePipe;
    DWORD dwWaitResult = WAIT_TIMEOUT, dwBytesRead, dwExitCode, dwSizeLow, dwSizeHigh, dwError;
    char cReadLine[MAX_LINE_LENGTH];
    BOOL bDoRead = TRUE, bOK = TRUE;
    MSG AppMsg;

    ZeroMemory(&amp;si, sizeof(si));
    si.cb = sizeof(si);

    //Pipes erzeugen
    sa.nLength=sizeof(sa);
    sa.bInheritHandle=TRUE;
    sa.lpSecurityDescriptor=NULL;
    bOK = CreatePipe(&amp;hReadPipe, &amp;hWritePipe, &amp;sa, 1048576);
    if(!bOK)
    {
        //FEHLER
        dwError = GetLastError();
        bOK = FALSE;
        goto PROCESS_END_NOPIPE;
    }

    //Pipes eintragen
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
    si.hStdOutput = hWritePipe;                        //Schreib-Ende der Pipe an Prozess übergeben
    si.hStdError = hWritePipe;                        //Schreib-Ende der Pipe an Prozess übergeben
    si.wShowWindow = SW_SHOWMINNOACTIVE;

    //Prozess starten
    bOK = CreateProcess(NULL,
                        pcCommandLine,
                        NULL,
                        NULL,
                        TRUE,
                        NORMAL_PRIORITY_CLASS,
                        NULL,
                        NULL,
                        &amp;si,
                        &amp;pi);

    if(!bOK)
    {
        //FEHLER
        dwError = GetLastError();
        goto PROCESS_END_NOPROC;
    }

    //Auf Ende warten und Messages lesen
    while(dwWaitResult != WAIT_OBJECT_0)
    {
        dwWaitResult = WaitForSingleObject(pi.hProcess, 10);
        while(dwSizeLow = GetFileSize(hReadPipe, &amp;dwSizeHigh))
        {
            ZeroMemory(cReadLine, MAX_LINE_LENGTH);
            //Aus dem Leseende der Pipe die Progzessausgaben lesen
            if(bDoRead = ReadFile(hReadPipe, cReadLine, MAX_LINE_LENGTH - 1, &amp;dwBytesRead, NULL))
            {
                if(dwBytesRead)
                {
                    //**** hier Programmausgabe verarbeiten (z.B. send) *******
                    send(s, cReadLine, strlen(cReadLine), 0);
                }
            }
            else
            {
                bOK = FALSE;
                dwError = GetLastError();
            }
        }
        //Applikations-Messagequeue verarbeiten
        if(PeekMessage(&amp;AppMsg, 0, 0, 0, PM_NOREMOVE))
        {
            GetMessage(&amp;AppMsg, 0, 0, 0);
            TranslateMessage(&amp;AppMsg);
            DispatchMessage(&amp;AppMsg);
        }
    }

    if(bOK)
    {
        bOK = GetExitCodeProcess(pi.hProcess, &amp;dwExitCode);
        if(bOK)
        {
            if(dwExitCode != 0)
            {
                //Prozess kehrt mit Ergebnis != 0 zurück
                bOK = FALSE;
            }
        }
        else
        {
            //FEHLER im GetExitCodeProcess
            dwError = GetLastError();
            bOK = FALSE;
        }
    }

    //Close handles
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);

PROCESS_END_NOPROC:
    CloseHandle(hWritePipe);
    CloseHandle(hReadPipe);

PROCESS_END_NOPIPE:
    return bOK;
}

int main(int argc, char* argv[]) 
{ 
    if(argc &gt; 1)
    {
        //Startet auf dem übergebenem PORT
        int PORT = atoi(argv[1]);

       // SOCKET welcher neue Verbindungen annimmt 
       // SOCKET which accepts new connections 
       SOCKET acceptSocket; 
       SOCKADDR_IN addr; 
       int rc,addrsize=sizeof(SOCKADDR_IN); 
       unsigned int i,j; 
       // fd_set 
       fd_set fdSetRead; 
       // timout für select() / timeout for select() 
       timeval selectTimeout; 
       // temporär benutz für neue verbindungen 
       // temporary used for new connections 
       Connection newConnection; 
       // buffer 
       char buf[1024]; 

       // clients array leeren / clear clients array 
       memset(clients,0x0,sizeof(Connection)*MAX_CLIENTS); 

       // start winsock 
       rc=startWinsock(); 
       if(rc==SOCKET_ERROR) 
          return 1; 

       // socket erstellen / create socket 
       acceptSocket=socket(PF_INET,SOCK_STREAM,0); 
       if(acceptSocket==INVALID_SOCKET) 
       { 
          printf(&quot;Error, cannot create socket: %d\n&quot;,WSAGetLastError()); 
          return 1; 
       } 

       // sockt an port 1234 binden / bind socket to port 1234 
       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) 
       { 
          printf(&quot;Error, bind() failed: %d\n&quot;,WSAGetLastError()); 
          return 1; 
       } 

       // auf verbindungen warten / listen for connections 
       rc=listen(acceptSocket,10); 
       if(rc==SOCKET_ERROR) 
       { 
          printf(&quot;Error,listen() failed: %d\n&quot;,WSAGetLastError()); 
          return 1; 
       } 

       // The parameter readfds identifies the sockets that are to be checked for readability. 
       // If the socket is currently in the listen state, it will be marked as readable if an 
       // incoming connection request has been received such that an accept is guaranteed to 
       // complete without blocking. 

       while(1) 
       { 

          // fd_set leeren / clear fd_set 
          FD_ZERO(&amp;fdSetRead); 

          // den socket welcher verbindungen annimmt hinzufügen 
          // add the SOCKET which accepts new connections 

          FD_SET(acceptSocket,&amp;fdSetRead); 
          // alle clients hinzufügen 
          // add all clients 
          for(i=0;i&lt;MAX_CLIENTS;i++) 
          { 
             if(clients[i].used) 
                FD_SET(clients[i].socket,&amp;fdSetRead); 
          } 

          // warten bis irgend ein socket bereit ist, wenn timout NULL ist kehrt select() 
          // erst zurück wenn ein socket bereit ist, select() blockt also in diesem falle 
          // wait until any socket is ready (timeout = NULL, block until one socket is ready) 
          rc=select(0,&amp;fdSetRead,NULL,NULL,NULL); 

          // abbrechen bei einem fehler 
          // break on error 
          if(rc&lt;1) 
             break; 

          printf(&quot;select() returned %d ready sockets\n&quot;,rc); 

          for(i=0;i&lt;fdSetRead.fd_count;i++) 
          { 

             // acceptSocket ? 
             if(fdSetRead.fd_array[i]==acceptSocket) 
             { 
                // verbindung annehmen / accept new connection 
                newConnection.socket=accept(acceptSocket,(SOCKADDR*)&amp;newConnection.addr,&amp;addrsize); 
                rc=getFreeClientSlot(); 
                if(rc==-1) 
                { 
                   printf(&quot;Cannot accept new clients\n&quot;); 
                   continue; 
                } 
                // zu den clients hinzufügen 
                // add to clients 
                clients[rc]=newConnection; 
                clients[rc].used=true; 
                printf(&quot;New Client accepted from %s\n&quot;,inet_ntoa(newConnection.addr.sin_addr)); 
                continue; 
             } 

             // ein client ? 
             // a client ? 
             for(j=0;j&lt;MAX_CLIENTS;j++) 
             { 
                if(!clients[j].used) 
                   continue; 

                if(clients[j].socket==fdSetRead.fd_array[i]) 
                { 
                   rc=recv(clients[j].socket,buf,1023,0); 
                   buf[rc]='\0'; 
                   // rc==0 =&gt; client hat die verbindung beendet 
                   if(rc==0) { 
                      printf(&quot;Client %d (%s): closed connection\n&quot;,j,inet_ntoa(clients[j].addr.sin_addr)); 
                      closesocket(clients[j].socket); 
                      clients[j].erase(); 
                      continue; 
                   // rc==SOCKET_ERROR =&gt; fehler, verbindung beenden! 
                   } 
                   else if(rc==SOCKET_ERROR) 
                   { 
                      printf(&quot;Client %d (%s): Error %d\n&quot;,j,inet_ntoa(clients[j].addr.sin_addr),WSAGetLastError()); 
                      printf(&quot;Client %d (%s): Server aborts connection\n&quot;,j,inet_ntoa(clients[j].addr.sin_addr)); 
                      closesocket(clients[j].socket); 
                      clients[j].erase(); 
                      continue; 
                   // daten empfangen und an alle clients senden 
                   } 
                   else 
                   { 
                       printf(&quot;Client %d (%s): Befehl: '%s' \n&quot;,j,inet_ntoa(clients[j].addr.sin_addr),buf); 
                      //sendToAllClients(buf); 

                      string command = buf;
                      if(command.find(' ') != string::npos)
                      {                          
                          int pos = command.find(' ');   
                          int lang = command.length();
                            string task = command.substr(0,pos);
                          string para = command.substr(pos+1,lang);

                          string str;
                          str += '&quot;';
                          str += reg.xmd_GetValue(&quot;bin&quot;);
                          str += &quot;\\&quot;;
                          str += task;
                          str += &quot;.exe&quot;;
                          str += '&quot;';
                          str += &quot; &quot; + para;

                          cout &lt;&lt; &quot;Erfolgreich: &quot; &lt;&lt; ProcessCommandLine(cvt.StringToChar(str), clients[j].socket) &lt;&lt; endl;
                      }

                      else
                      {                            
                         if(command == &quot;close&quot;)                        
                         {
                             //rc=send(clients[i].socket,msg,strlen(msg),0); 
                             //  rc=send(clients[j].socket,task.c_str(),strlen(task.c_str()),0); 
                             closesocket(acceptSocket); 
                             WSACleanup();
                         }                         
                         cout &lt;&lt; &quot;Erfolgreich: &quot; &lt;&lt; ProcessCommandLine(cvt.StringToChar(command), clients[j].socket) &lt;&lt; endl;
                      }          

                   } 
                } 
             } 
          }

          cout &lt;&lt; &quot;-----------------------------------&quot; &lt;&lt; endl;
       }//Ende while

       // aufräumen 
       closesocket(acceptSocket); 
       WSACleanup();        
    }
    else 
    {
        cout &lt;&lt; &quot;server PORT&quot; &lt;&lt; endl;
    }

    return 0;   
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1140940</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1140940</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Wed, 20 Sep 2006 09:29:44 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Wed, 20 Sep 2006 09:40:44 GMT]]></title><description><![CDATA[<p>kernel64 schrieb:</p>
<blockquote>
<p>Könntet Ihr euch das bitte anschaun.</p>
</blockquote>
<p>versuch den fehler weiter einzugrenzen (bau z.b. überall debug-ausgaben ein)...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1140946</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1140946</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Wed, 20 Sep 2006 09:40:44 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Wed, 20 Sep 2006 16:33:09 GMT]]></title><description><![CDATA[<p>Habe im mittleren Teil vom Client folgendes eingefügt:</p>
<pre><code class="language-cpp">//Eingabe des Befehl
getline(cin, str);

rc=send(s,str.c_str(),strlen(str.c_str()),0); 
			if(rc==SOCKET_ERROR)
			{
				printf(&quot;Error: Sending to Server failed: %d\n&quot;,WSAGetLastError()); 
			} 

		cout &lt;&lt; &quot;vor While...&quot; &lt;&lt; endl;

			// fd_set und timeout vorbereiten 
			FD_ZERO(&amp;fdSetRead); 
			FD_SET(s,&amp;fdSetRead); 
			timeout.tv_sec=0; 
			timeout.tv_usec=0; 

			// prüfen ob ein socket bereit ist, da timeout=0 kehrt die funktion 
			// sofort wieder zurück nach dem aufruf. 
			// achtung: das timeout auf 0 setzen oder als paremeter NULL mitgeben 
			// ist NICHT das gleiche. auf 0 gesetzt kehrt sofort zurück, während NULL blockt. 
			while((rc=select(0,&amp;fdSetRead,NULL,NULL,&amp;timeout))&gt;0) 
			{
			cout &lt;&lt; &quot;in while...&quot; &lt;&lt; endl;

				rc=recv(s,buf,1024,0); 
				// server hat die verbindung beendet ? 
				if(rc==0) 
				{ 
					printf(&quot;Server closed connection!\n&quot;); 
					return 1; 
				// fehler: beenden! 
				} 
				else if(rc==SOCKET_ERROR) 
				{ 
					printf(&quot;Error: recv failed: %d\n&quot;,WSAGetLastError()); 
					return 1; 
				} 
			cout &lt;&lt; &quot;empfange...&quot; &lt;&lt; endl;
				// empfangene daten ausgeben 
				buf[rc]='\0'; 
				cout &lt;&lt; buf &lt;&lt; endl;
			} 

		cout &lt;&lt; &quot;nach While()&quot; &lt;&lt; endl;
</code></pre>
<p>Folgendes passiert wenn ich test eingebe: (test ist eine test.exe mit einer Ausgabe)</p>
<blockquote>
<p>Eingabe: test //test dann Enter<br />
vor While...<br />
nach While()<br />
//keine Ausgabe</p>
<p>Eingabe: //hier nichts eingegeben und dann Enter gedrückt<br />
vor While...<br />
in While...<br />
empfange...<br />
....//Hier kommt die Ausgabe von <strong>test</strong><br />
nach while()</p>
</blockquote>
<p>Wie man sieht wird bei der ersten eingabe die while schleife nicht abgearbeitet.<br />
Woran kann das liegen ist der server fehlerhaft??<br />
Bitte um Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141339</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141339</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Wed, 20 Sep 2006 16:33:09 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Wed, 20 Sep 2006 20:47:51 GMT]]></title><description><![CDATA[<p>Hi</p>
<p>Hab ehrlich gesagt keine Lust, deinen kompletten Code durchzusehen (bin aber drübergeflogen). Und ein Tip: Poste nicht zuviel Code (das da ist <em>definitiv</em> zu viel! Das treibt nämlich potenziellen Helfern die Lust am helfen aus!<br />
&lt;- Nicht böse gemeint <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="😉"
    /></p>
<p>Zu deinem Problem:<br />
Wenn man die Ausgabe richtig deutet, wird in deinem Fall bei der Eingabe von &quot;test&quot; folgende Zeile</p>
<pre><code class="language-cpp">while((rc=select(0,&amp;fdSetRead,NULL,NULL,&amp;timeout))&gt;0)
</code></pre>
<p>abgearbeitet und select gibt irgendwas kleiner gleich 0 zurück. Logisch, oder? Immerhin geht er gar nicht erst in die Schleife rein. Also finde am besten erstmal raus, warum select &lt;= 0 zurückgibt. Gib für diesen Fall z.B. mal &quot;rc&quot; aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141463</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141463</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Wed, 20 Sep 2006 20:47:51 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Wed, 20 Sep 2006 21:45:05 GMT]]></title><description><![CDATA[<p>Hab folgendes ergänzt:</p>
<pre><code class="language-cpp">//vor der schleife
cout &lt;&lt; &quot;vor While...&quot; &lt;&lt; endl;
cout &lt;&lt; &quot;rc:&quot; &lt;&lt; rc &lt;&lt; endl;

while((rc=select(0,&amp;fdSetRead,NULL,NULL,&amp;timeout))&gt;0) 
{
cout &lt;&lt; &quot;in while...&quot; &lt;&lt; endl;
				cout &lt;&lt; &quot;rc:&quot; &lt;&lt; rc &lt;&lt; endl;

//...

}
cout &lt;&lt; &quot;nach While()&quot; &lt;&lt; endl;
			cout &lt;&lt; &quot;rc:&quot; &lt;&lt; rc &lt;&lt; endl;
</code></pre>
<p>Folgendes wird ausgegeben wenn ich ein Befehl eingebe:</p>
<blockquote>
<p>Eingabe: test //Befehl<br />
vor While...<br />
rc:4<br />
nach While()<br />
rc:0</p>
<p>Eingabe: //hier nichts eingegeben und dann Enter gedrückt<br />
vor While...<br />
rc:0<br />
in while...<br />
rc:1<br />
empfange...<br />
...//Hier kommt die Ausgabe von test<br />
nach While()<br />
rc:0</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1141483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141483</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Wed, 20 Sep 2006 21:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Wed, 20 Sep 2006 21:55:53 GMT]]></title><description><![CDATA[<p>Das ist doch schonmal was! Aber könntest ja auch mal selber versuchen, deine Ausgaben zu interpretieren :p</p>
<p>Naja, also:<br />
Bei dieser Ausgabe: &quot;cout &lt;&lt; &quot;rc:&quot; &lt;&lt; rc &lt;&lt; endl;&quot; ist rc ja der Rückgabewert von send(...). Nachschauen-&gt; send gibt die Anzahl von Bytes zurück, die gesendet wurden. Also wurden erfolgreich die 4 Bytes (&quot;test&quot;) gesendet! Das funktioniert also!<br />
Der Eintritt in die While-Schleife scheitert und select hat 0 zurückgegeben. Bedeutet, dass nix angekommen ist, in dieser kurzen Zeit.<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /><br />
Bei der nächsten Eingabe (bei dir &quot;&quot; &lt;-Nix) ruft er wieder select auf und siehe da <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /> <em>Es wartet ein Paket</em>.<br />
Daraus könnte man schlussfolgern, dass das erste select so schnell aufgerufen wurde (direkt nach dem senden), dass das Paket in der kurzen Zeit noch gar nicht angekommen ist!<br />
Ist das nicht eine Erkenntnis <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> ? Lass dem Paket also ein bisschen Zeit, dann müsste es funktionieren, scheint ja sonst alles korrekt zu sein.</p>
<p>Mit freundlichen Grüßen,<br />
Badestrand</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141487</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141487</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Wed, 20 Sep 2006 21:55:53 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Thu, 21 Sep 2006 10:51:47 GMT]]></title><description><![CDATA[<p>Das was du meinst hab ich auch die ganze Zeit gedacht, dass beim Client die Daten viel zu früh erwartet werden. Hab den Client mal mit dem debugger gestartet also mit F10 und gabs keine Probleme, da hier alles Schritt für Schritt abgearbeitet wird, deshalb sind alle Daten angekommen.</p>
<pre><code class="language-cpp">Lass dem Paket also ein bisschen Zeit, dann müsste es funktionieren, scheint ja sonst alles korrekt zu sein.
</code></pre>
<p>Also ich werde ein Sleep(1000) einbauen, mal sehn wie es dann läuft.<br />
Danke nochmals für die Erkenntnis.</p>
<p>[Edit] Es funktioniert danke <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="🙂"
    /> habe für Sleep(500) eingesetzt müsste ausreichen.<br />
Wie sieht es mit dem Buffer aus, der dritte parameter bei recv() send()?</p>
<pre><code class="language-cpp">recv(s,buf,1024,0);
</code></pre>
<p>Soll da 1024 oder 1023 stehn?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141698</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141698</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Thu, 21 Sep 2006 10:51:47 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Thu, 21 Sep 2006 11:32:14 GMT]]></title><description><![CDATA[<p>Bin froh, dass es doch noch geklappt hat!</p>
<p>kernel64 schrieb:</p>
<blockquote>
<p>Wie sieht es mit dem Buffer aus, der dritte parameter bei recv() send()?</p>
<pre><code class="language-cpp">recv(s,buf,1024,0);
</code></pre>
<p>Soll da 1024 oder 1023 stehn?</p>
</blockquote>
<p>Da dein Buffer 1024 Byte groß ist, stimmt das schon mit der 1024. Da du allerdings das letzte Zeichen auf '\0' setzt, mach lieber 1023. Wenn du nämlich 1024 Bytes an Daten empfängst (Rückgabewert rc=1024), dann schreibst du mit &quot;Buf[rc]='\0';&quot; in das 1025-ste Byte. Das wär zuviel.</p>
<p>Mfg,<br />
badestrand</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141734</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141734</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Thu, 21 Sep 2006 11:32:14 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Thu, 21 Sep 2006 12:37:47 GMT]]></title><description><![CDATA[<p>Vielen vielen Dank, endlich klappts <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 />
Hatte immer ein fehler wenn ich den client beendet habe:</p>
<blockquote>
<p>'buf' Stack corrupted</p>
</blockquote>
<p>Wahrscheinlich wegen denn 1024</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141787</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Thu, 21 Sep 2006 12:37:47 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Thu, 21 Sep 2006 13:09:44 GMT]]></title><description><![CDATA[<p>Noch ne kleine Frage nebenbei, wie soll ich folgendes senden:</p>
<pre><code class="language-cpp">string pc;
		pc += &quot;host:&quot;;
		pc += ComputerName();
		pc += &quot;\n&quot;;
</code></pre>
<p>Habe es so gemacht:</p>
<pre><code class="language-cpp">send(s, pc.c_str(), pc.length(), 0);
</code></pre>
<p>Wie würdest du das machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141824</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Thu, 21 Sep 2006 13:09:44 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Thu, 21 Sep 2006 13:18:20 GMT]]></title><description><![CDATA[<p>kernel64 schrieb:</p>
<blockquote>
<p>Habe es so gemacht:</p>
<pre><code class="language-cpp">send(s, pc.c_str(), pc.length(), 0);
</code></pre>
<p>Wie würdest du das machen?</p>
</blockquote>
<p>Kannste doch so machen, allerdings kannste zur Verkettung auch das machen:</p>
<pre><code class="language-cpp">string pc(string(&quot;host:&quot;) + string(ComputerName()) + string(&quot;\n&quot;));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1141837</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141837</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 21 Sep 2006 13:18:20 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Thu, 21 Sep 2006 15:51:30 GMT]]></title><description><![CDATA[<p>Aber wie sieht das Empfangen auf der Gegenseite aus, also welche größe soll bei recv() dann verwendet werden? Die göße von <strong>pc</strong> ist ja dynamisch!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141981</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141981</guid><dc:creator><![CDATA[kernel64]]></dc:creator><pubDate>Thu, 21 Sep 2006 15:51:30 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe beim Client&#x2F;Server... on Thu, 21 Sep 2006 18:52:06 GMT]]></title><description><![CDATA[<p>Du kannst ja einfach auch einen Puffer von 1024 Bytes nehmen. Wenn recv(...) dann einen Wert von 1024 zurückgibt, besteht eine gute Chance, dass noch mehr Bytes warten. Es werden dann ja schließlich nicht mehr als 1024 in deinen Puffer geschrieben!<br />
Also dann Puffer vergrößern <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /> Dynamischer Puffer mit new[] und delete[] oder malloc, realloc(!) und free anlegen.</p>
<pre><code>- Puffer anlegen mit 1024 Bytes Größe
- recv mit 1024 aufrufen
- Wenn recv 1024 zurückgibt, dann Puffer vergrößern und immer wieder recv mit wieder 1024 und richtiger Pufferposition aufrufen, bis recv&lt;1024
- Dann letztes Byte auf '\0' setzen und ausgeben
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1142135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1142135</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Thu, 21 Sep 2006 18:52:06 GMT</pubDate></item></channel></rss>