<?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[JPG über sockets!]]></title><description><![CDATA[<p>hallo,<br />
ich habe eine verbindung über sockets aufgebaut.<br />
Wie kann ich jetzt eine datei genauer ein .jpg versenden?<br />
Ich weiß mit send kann ich text versenden. aber wie eine datei?<br />
Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/222542/jpg-über-sockets</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 16:20:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/222542.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 14 Sep 2008 12:19:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:19:22 GMT]]></title><description><![CDATA[<p>hallo,<br />
ich habe eine verbindung über sockets aufgebaut.<br />
Wie kann ich jetzt eine datei genauer ein .jpg versenden?<br />
Ich weiß mit send kann ich text versenden. aber wie eine datei?<br />
Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581686</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581686</guid><dc:creator><![CDATA[dateien versenden]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:19:22 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:23:18 GMT]]></title><description><![CDATA[<p>dateien versenden schrieb:</p>
<blockquote>
<p>Ich weiß mit send kann ich text versenden. aber wie eine datei?</p>
</blockquote>
<p>Wo kommt das eigentlich immer her, dass man mit send nur Text verschicken könnte!? Mit send kannst du verschicken was du willst, also einfach Datei in den Speicher laden (komplett oder blockweise) und wegschicken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581689</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:23:18 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:26:30 GMT]]></title><description><![CDATA[<p>ja das ist mir klar nur wie kann ich die datei laden?<br />
Einfach den Pfad angeben bei send?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581690</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581690</guid><dc:creator><![CDATA[dateien versenden]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:26:30 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:28:41 GMT]]></title><description><![CDATA[<p>lol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581692</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581692</guid><dc:creator><![CDATA[asdca]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:28:41 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:29:38 GMT]]></title><description><![CDATA[<p>öhm könnt ihr euch nur über anfänger lustig machen?<br />
Ich hab halt noch nicht so viel Erfahrung wie ihr tut mir leid...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581693</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581693</guid><dc:creator><![CDATA[dateien versenden]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:29:38 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:30:21 GMT]]></title><description><![CDATA[<p>dann lies ein buch über die grundlagen der c programmierung und komm dann wieder.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581694</guid><dc:creator><![CDATA[asdca]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:30:21 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:31:28 GMT]]></title><description><![CDATA[<p>-.- ich weiß selber das es totaler blödsinn ist einfach den Pfad anzugeben. Das wäre ja so als ob ich text versenden würde! Nur wie kann ich das in den Speicher laden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581695</guid><dc:creator><![CDATA[dateien versenden]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:31:28 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:32:27 GMT]]></title><description><![CDATA[<p>asdca schrieb:</p>
<blockquote>
<p>dann lies ein buch über die grundlagen der c programmierung und komm dann wieder.</p>
</blockquote>
<p>fopen, fseek, fread, fwrite, fclose. CreateFile, ReadFile, CloseHandle.</p>
<p>Wir sind hier kein Kindergarten. <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="➡"
    /> <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="➡"
    /> <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="➡"
    /> <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="➡"
    /> <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="➡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581696</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581696</guid><dc:creator><![CDATA[asdca]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:32:27 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:34:51 GMT]]></title><description><![CDATA[<p>so?<br />
ifstream file;<br />
file.open(&quot;.jpg&quot;,ios::in|ios::binary);</p>
<p>send(s,file,sizeof(file),0);<br />
file.close();</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581698</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581698</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:34:51 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:35:21 GMT]]></title><description><![CDATA[<p>was soll das für schrott sein? das sieht voll hässlich aus, hier ist Winapi und kein schrott c++ forum.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581700</guid><dc:creator><![CDATA[asdca]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:35:21 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:44:01 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">FILE * pFile;
  long lSize;
  char * buffer;
  size_t result;

  pFile = fopen ( &quot;myfile.bin&quot; , &quot;rb&quot; );
  if (pFile==NULL) {fputs (&quot;File error&quot;,stderr); 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 (sizeof(char)*lSize);
  if (buffer == NULL) {fputs (&quot;Memory error&quot;,stderr); exit (2);}

  // copy the file into the buffer:
  result = fread (buffer,1,lSize,pFile);
  if (result != lSize) {fputs (&quot;Reading error&quot;,stderr); exit (3);}

  /* the whole file is now loaded in the memory buffer. */

  // buffer hier jetzt noch über send verschicken und fertig?
  // enthält buffer die ganze datei oder muss ich mehrere teile schicken?

  // terminate
  fclose (pFile);
  free (buffer);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1581702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581702</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:44:01 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 12:57:38 GMT]]></title><description><![CDATA[<p>und wie kann ich dann aus dem empfangegen buffer wieder eine datei erstellen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581707</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 12:57:38 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 13:05:33 GMT]]></title><description><![CDATA[<p>asdca schrieb:</p>
<blockquote>
<p>hier ist Winapi und kein schrott c++ forum.</p>
</blockquote>
<p>Ob der Thread-Ersteller C oder C++ programmieren will, sei ihm immer noch freigestellt.</p>
<p>omg schrieb:</p>
<blockquote>
<p>so?<br />
ifstream file;<br />
file.open(&quot;.jpg&quot;,ios::in|ios::binary);</p>
<p>send(s,file,sizeof(file),0);<br />
file.close();</p>
</blockquote>
<p>Fast <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>
<pre><code class="language-cpp">ifstream file( &quot;bla.jpg&quot;, ios::binary );

// Dateigröße ermitteln
file.seekg( 0, ios::end );
size_t length = file.tellg();
file.seekg( 0, ios::beg );

// in Buffer einlesen
vector&lt;char&gt; buffer( length );
file.read( &amp;buffer[0], length );

// und ab damit
send( s, &amp;buffer[0], length, 0 );
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1581709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581709</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sun, 14 Sep 2008 13:05:33 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 13:05:02 GMT]]></title><description><![CDATA[<p>omg schrieb:</p>
<blockquote>
<p>und wie kann ich dann aus dem empfangegen buffer wieder eine datei erstellen?</p>
</blockquote>
<p>Dazu musst du natürlich vorher mitschicken, wie groß die Datei ist, also beim Senden noch <code>send( s, &amp;length, sizeof(length), 0 );</code> .<br />
Beim Empfangen halt erst die Länge der Datei empfangen (sizeof(length), sizeof(length) muss aber bei Empfänger und Sender gleich sein!) und dann solange empfangen, bis die Datei komplett da ist (eben bis 'length' Bytes gelesen sind).</p>
<p>edit: Programmierst du eigentlich mit C oder mit C++?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581711</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sun, 14 Sep 2008 13:05:02 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 13:16:11 GMT]]></title><description><![CDATA[<p>vielen vielen dank Badestrand!! ich programmiere C++.<br />
Aber wenn ich jetzt die bytes empfangen habe muss ich ja auch irgendwie die Datei wieder erstellen am Empfänger also das Bild.<br />
Und noch ne Frage: da steht binary bei fopen.<br />
Gehen da trotzdem bilder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581717</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 13:16:11 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 13:27:09 GMT]]></title><description><![CDATA[<p>omg schrieb:</p>
<blockquote>
<p>vielen vielen dank Badestrand!! ich programmiere C++.</p>
</blockquote>
<p>Das ist gut <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="🙂"
    /> Du könntest dir auch mal <a href="http://www.sfml-dev.org/tutorials/1.3/network-sockets.php" rel="nofollow">SFML</a> anschauen, damit ist das Socket-Handling um einiges einfacher.</p>
<p>omg schrieb:</p>
<blockquote>
<p>Aber wenn ich jetzt die bytes empfangen habe muss ich ja auch irgendwie die Datei wieder erstellen am Empfänger also das Bild.</p>
</blockquote>
<p>Genau, einfach mit <code>ofstream</code> eine schreibende Datei mit Endung &quot;.jpg&quot; erzeugen/öffnen und den Dateiinhalt reinschreiben. Dann kannst du sie ganz normal im Explorer öffnen.</p>
<p>omg schrieb:</p>
<blockquote>
<p>Und noch ne Frage: da steht binary bei fopen.<br />
Gehen da trotzdem bilder?</p>
</blockquote>
<p>Ja klar, &quot;binary&quot; ist allumfassend, alle Daten sind binär. Textdaten oder Bilddaten sind auch binär, werden aber besonders dargestellt (eben als Text/Bild), weil sie vom Computer erst nach bestimmten Standards (siehe Dateiformat von Jpegs oder ASCII-Format) interpretiert werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581724</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sun, 14 Sep 2008 13:27:09 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 13:38:11 GMT]]></title><description><![CDATA[<p>ok danke<br />
send( s, &amp;length, sizeof(length), 0 );<br />
konvertierung des 2 paramteter von size_t in char nicht möglich oO</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581729</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 13:38:11 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 13:42:33 GMT]]></title><description><![CDATA[<p>Evtl. <code>send( s, static_cast&lt;const char*&gt;(&amp;length), sizeof(length), 0 );</code> ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581730</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sun, 14 Sep 2008 13:42:33 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 14:01:02 GMT]]></title><description><![CDATA[<p>soweit bin ich schon:<br />
Server</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;

using namespace std;

int main()
{
 	WSADATA wsa;
	SOCKADDR_IN addr;
	int rc;
	SOCKET acceptSocket, connectedSocket;
	if(WSAStartup(MAKEWORD(2,0), &amp;wsa) != 0)
	{
		cout &lt;&lt; &quot;Socket konnte nicht gestartet werden&quot; &lt;&lt; endl;
	}
	acceptSocket = socket(AF_INET,SOCK_STREAM,0);
	if(acceptSocket==INVALID_SOCKET)
	{
		cout &lt;&lt; &quot;Socket konnte nicht erstellt werden&quot; &lt;&lt; endl;
	}
	memset(&amp;addr,0,sizeof(SOCKADDR_IN));
	addr.sin_family=AF_INET;
	addr.sin_port=htons(40791);
	addr.sin_addr.s_addr=INADDR_ANY;
	if(bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
	{
		cout &lt;&lt; &quot;Socket konnte nicht gebindet werden&quot; &lt;&lt; endl;
	}
	if(listen(acceptSocket,10)==SOCKET_ERROR)
	{
		cout &lt;&lt; &quot;listen ist fehlgeschlagen&quot; &lt;&lt; endl;
	}
	connectedSocket=accept(acceptSocket,NULL,NULL);
	if(connectedSocket==INVALID_SOCKET)
	{
		cout &lt;&lt; &quot;Socket konnte nicht akzeptiert werden&quot; &lt;&lt; endl;
	}
	size_t length;
	recv(connectedSocket, (char *)length, sizeof(length), 0);
	cout &lt;&lt; length &lt;&lt; endl;
	system(&quot;PAUSE&quot;);
	return 0;
}
</code></pre>
<p>Client:</p>
<pre><code class="language-cpp">int main()
{

	SOCKET s;
	WSADATA wsa;
	SOCKADDR_IN addr;
	int rc;
	if(WSAStartup(MAKEWORD(2, 0), &amp;wsa) != 0)
	{
		cout &lt;&lt; &quot;Winsock konnte nicht gestartet werden&quot; &lt;&lt; endl;
	}
	s = socket(AF_INET, SOCK_STREAM, 0);
	if(s == INVALID_SOCKET) 
	{
		cout &lt;&lt; &quot;Socket konnte nicht erstellt werden&quot; &lt;&lt; endl;
	}
	memset(&amp;addr, 0, sizeof(SOCKADDR_IN)); // zuerst alles auf 0 setzten 
	addr.sin_family = AF_INET;
	addr.sin_port = htons(40791); // wir verwenden mal port 40791
	rc = getAddrFromString(TEXT(&quot;ip&quot;), &amp;addr);
	if(rc == SOCKET_ERROR)
	{
		cout &lt;&lt; &quot;IP konnte nicht aufgelöst werden&quot; &lt;&lt; endl;
	}
    if(connect(s, (SOCKADDR*)&amp;addr, sizeof(SOCKADDR)) == SOCKET_ERROR) 
	{
		cout &lt;&lt; &quot;Konnte nicht verbinden&quot; &lt;&lt; endl;
	}
	ifstream file( &quot;tmp.jpg&quot;, ios::binary );
	// Dateigröße ermitteln
	file.seekg( 0, ios::end );
	size_t length = file.tellg();
	file.seekg( 0, ios::beg );
	// in Buffer einlesen
	vector&lt;char&gt; buffer( length );
	file.read( &amp;buffer[0], length );
	// und ab damit
	send( s, (const char*)length, sizeof(length), 0 );
[cpp]
</code></pre>
<p>leider gibt der Server immer 7143525 aus, egal wie groß die datei ist.<br />
Woran kann das liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581740</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581740</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 14:01:02 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 14:03:50 GMT]]></title><description><![CDATA[<p>&amp;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581742</guid><dc:creator><![CDATA[asdca]]></dc:creator><pubDate>Sun, 14 Sep 2008 14:03:50 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 14:10:55 GMT]]></title><description><![CDATA[<p>ahh danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581744</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 14:10:55 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 14:11:49 GMT]]></title><description><![CDATA[<p>jedoch gibt das immer noch 2 kbs oder so dazu.<br />
Wenn die datei so 63 kb groß ist gibt es 65781 und so aus.<br />
Ist das normal?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581746</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 14:11:49 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 14:28:19 GMT]]></title><description><![CDATA[<p>Server:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;fstream&gt;

using namespace std;

int main()
{
 	WSADATA wsa;
	SOCKADDR_IN addr;
	int rc;
	SOCKET acceptSocket, connectedSocket;
	if(WSAStartup(MAKEWORD(2,0), &amp;wsa) != 0)
	{
		cout &lt;&lt; &quot;Socket konnte nicht gestartet werden&quot; &lt;&lt; endl;
	}
	acceptSocket = socket(AF_INET,SOCK_STREAM,0);
	if(acceptSocket==INVALID_SOCKET)
	{
		cout &lt;&lt; &quot;Socket konnte nicht erstellt werden&quot; &lt;&lt; endl;
	}
	memset(&amp;addr,0,sizeof(SOCKADDR_IN));
	addr.sin_family=AF_INET;
	addr.sin_port=htons(40791);
	addr.sin_addr.s_addr=INADDR_ANY;
	if(bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
	{
		cout &lt;&lt; &quot;Socket konnte nicht gebindet werden&quot; &lt;&lt; endl;
	}
	if(listen(acceptSocket,10)==SOCKET_ERROR)
	{
		cout &lt;&lt; &quot;listen ist fehlgeschlagen&quot; &lt;&lt; endl;
	}
	connectedSocket=accept(acceptSocket,NULL,NULL);
	if(connectedSocket==INVALID_SOCKET)
	{
		cout &lt;&lt; &quot;Socket konnte nicht akzeptiert werden&quot; &lt;&lt; endl;
	}
	size_t length;
	recv(connectedSocket, (char *)&amp;length, sizeof(length), 0);
	vector&lt;char&gt; buffer( length );
	cout &lt;&lt; length &lt;&lt; endl;
	recv(connectedSocket, &amp;buffer[0], length, 0);
	int i = 0;
    ofstream Zieldatei(&quot;tmp.jpg&quot;);          
    if (!Zieldatei)                             // Fehler beim Öffnen?
		cerr &lt;&lt; &quot;Ausgabe-Datei kann nicht geöffnet werden\n&quot;; 
    else {            // falls es funktioniert hat 
		while(i != length)
        Zieldatei.put(buffer[i]);   
		cout &lt;&lt; &quot;erfolgreicht&quot; &lt;&lt; endl;
	}
	system(&quot;PAUSE&quot;);
	return 0;
}
</code></pre>
<p>Client ausschnitt</p>
<pre><code class="language-cpp">ifstream file( &quot;tmp.jpg&quot;, ios::binary );
	// Dateigröße ermitteln
	file.seekg( 0, ios::end );
	size_t length = file.tellg();
	file.seekg( 0, ios::beg );
	// in Buffer einlesen
	vector&lt;char&gt; buffer( length );
	file.read( &amp;buffer[0], length );
	// und ab damit
	cout &lt;&lt; length &lt;&lt; endl;
	send( s, (const char*)&amp;length, sizeof(length), 0 );
	Sleep(1000);
	send( s, &amp;buffer[0], length, 0 );
</code></pre>
<p>verdammt was mach ich nur falsch <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="😞"
    /><br />
manchmal gibt der server gar nicht erfolgreich aus aber der Client ist schon wieder abgeschlossen und manchmal klappt es aber bei der datei kommt immer fehler bei der vorschau zum anschaun OO</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581757</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 14:28:19 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 15:08:02 GMT]]></title><description><![CDATA[<p>Das könnte daran liegen, dass recv nicht unbedingt immer alle Daten empfängt. Überprüf doch mal den Return-Wert von recv und du brauchst wohl eine Schleife, die solange empfängt, bis die Daten da sind. Oder auch 'ne Hilfsfunktion, die ungefähr so aussieht:</p>
<pre><code class="language-cpp">bool RecvData( SOCKET s, char* data, size_t bytes )
{
    size_t bytes_read = 0;
    while ( bytes_read != bytes )
    {
        int r = recv( s, data+bytes_read, bytes-bytes_read, 0 );

        // Grad keine Daten zum empfangen da?
        if ( r==-1 &amp;&amp; WSAGetLastError()==WSAEWOULDBLOCK )
            Sleep( 20 );
        // Fehler bzw Verbindung geschlossen?
        else if ( r &lt;= 0 )
            return false;
        else
            bytes_read += r;
    }
    return true;
}
</code></pre>
<p>edit: Der Code ist ungetestet. Und recv kann halt z.B. beim ersten Aufruf nur 5 Bytes empfangen, beim zweiten noch ein paar und beim dritten den Rest. Oder so, jedenfalls wartet es nicht, bis man die angegebene Anzahl an Bytes empfangen hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581766</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sun, 14 Sep 2008 15:08:02 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 15:49:36 GMT]]></title><description><![CDATA[<p>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="🙂"
    /><br />
jetzt wird die jpg jedes mal erstellt aber sie hat zirka 15 mb und kann nicht angezeigt werden <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>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;fstream&gt;

using namespace std;

char* RecvData( SOCKET s, size_t bytes );

int main()
{
 	WSADATA wsa;
	SOCKADDR_IN addr;
	int rc;
	SOCKET acceptSocket, connectedSocket;
	if(WSAStartup(MAKEWORD(2,0), &amp;wsa) != 0)
	{
		cout &lt;&lt; &quot;Socket konnte nicht gestartet werden&quot; &lt;&lt; endl;
	}
	acceptSocket = socket(AF_INET,SOCK_STREAM,0);
	if(acceptSocket==INVALID_SOCKET)
	{
		cout &lt;&lt; &quot;Socket konnte nicht erstellt werden&quot; &lt;&lt; endl;
	}
	memset(&amp;addr,0,sizeof(SOCKADDR_IN));
	addr.sin_family=AF_INET;
	addr.sin_port=htons(40791);
	addr.sin_addr.s_addr=INADDR_ANY;
	if(bind(acceptSocket,(SOCKADDR*)&amp;addr,sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
	{
		cout &lt;&lt; &quot;Socket konnte nicht gebindet werden&quot; &lt;&lt; endl;
	}
	if(listen(acceptSocket,10)==SOCKET_ERROR)
	{
		cout &lt;&lt; &quot;listen ist fehlgeschlagen&quot; &lt;&lt; endl;
	}
	connectedSocket=accept(acceptSocket,NULL,NULL);
	if(connectedSocket==INVALID_SOCKET)
	{
		cout &lt;&lt; &quot;Socket konnte nicht akzeptiert werden&quot; &lt;&lt; endl;
	}
	size_t length;
	recv(connectedSocket, (char *)&amp;length, sizeof(length), 0);
	cout &lt;&lt; length &lt;&lt; endl;
	char *buffer = RecvData(connectedSocket, length);
	int i = 0;
    ofstream Zieldatei(&quot;tmp.jpg&quot;);          
    if (!Zieldatei)                             // Fehler beim Öffnen?
		cerr &lt;&lt; &quot;Ausgabe-Datei kann nicht geöffnet werden\n&quot;; 
    else {            // falls es funktioniert hat 
		while(i != length)
        Zieldatei.put(buffer[i]);   
		cout &lt;&lt; &quot;erfolgreicht&quot; &lt;&lt; endl;
	}
	system(&quot;PAUSE&quot;);
	return 0;
}

char* RecvData( SOCKET s, size_t bytes )
{
    size_t bytes_read = 0;
	static char tempBuff[1000000];
    while ( bytes_read != bytes )
    {
        int r = recv( s, tempBuff+bytes_read, bytes-bytes_read, 0 );

        // Grad keine Daten zum empfangen da?
        if ( r==-1 &amp;&amp; WSAGetLastError()==WSAEWOULDBLOCK )
            Sleep( 20 );
        // Fehler bzw Verbindung geschlossen?
        else if ( r &lt;= 0 )
            return false;
        else
            bytes_read += r;
    }
    return tempBuff;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1581780</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581780</guid><dc:creator><![CDATA[omg]]></dc:creator><pubDate>Sun, 14 Sep 2008 15:49:36 GMT</pubDate></item><item><title><![CDATA[Reply to JPG über sockets! on Sun, 14 Sep 2008 15:59:55 GMT]]></title><description><![CDATA[<p>Also das mit dem tempBuff in RecvData ist aber ein bisschen dreckig <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="😃"
    /> Was gibt der Server denn bei <code>cout &lt;&lt; length &lt;&lt; endl;</code> aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1581785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1581785</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Sun, 14 Sep 2008 15:59:55 GMT</pubDate></item></channel></rss>