<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Comments for Tutorial for creating a threaded socket server and client application</title>
<link rel="alternate" type="text/plain" href="http://dn.codegear.com/article/26276" title="Tutorial for creating a threaded socket server and client application" />
<link rel="self" type="application/atom+xml" href="http://dn.codegear.com/article/26276/feed" title="Comments for Tutorial for creating a threaded socket server and client application" />
<id>http://dn.codegear.com/article/26276</id>
<updated>2008-11-19T05:24:18-08:00</updated>
<entry>
<title>Tutorial for creating a threaded socket server and client application</title>
<author>
<name>Pablo Carloni</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=40655</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=40655</id>
<updated>2007-11-12T11:21:09-08:00</updated>
<published>2007-11-12T11:21:09-08:00</published>
<summary>Tutorial for creating a threaded socket server and client application</summary>
<content>When I was trying to shutdown the server application, the thread threwan exception (ESocketError with message 'Read error 6, No valid controller').I don't know how to fix this problem. Any idea?The thread code is the next:const int BUFFERSIZE = (32*1024);void __fastcall TMyServerThread::ClientExecute( void ){  int ClientWaittTime = MainServerForm-&gt;TimeOut;  // make sure connection is active   while( !Terminated &amp;&amp; ClientSocket-&gt;Connected )   {     try     {       TWinSocketStream *pStream = new TWinSocketStream( ClientSocket, ClientWaittTime );             try       {         char buffer[BUFFERSIZE];         memset( buffer, 0, sizeof(buffer) );                 if( pStream-&gt;WaitForData( ClientWaittTime ) )        {            if( pStream-&gt;Read(buffer, sizeof(buffer)) == 0 )            {                         ClientSocket-&gt;Close(); // timeout: close the connection.           }           else            {               MainServerForm-&gt;Memo_Log-&gt;Lines-&gt;Add( AnsiString(&quot;(Client) &quot;) + AnsiString(buffer) );                           // Back again to Client:               pStream-&gt;Write( buffer, sizeof(buffer) );            }                    // ...            // Process requests here.            // ...                 }         else        {          ClientSocket-&gt;Close();        }      }       __finally       {         delete pStream;       }     }     catch (...)     {       HandleException();     }   }  MainServerForm-&gt;Memo_Log-&gt;Lines-&gt;Add( AnsiString( &quot;End of thread!!!&quot; ) );  } </content>
</entry>
<entry>
<title>re: Tutorial for creating a threaded socket server and client application</title>
<author>
<name>superpok superpok</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=39788</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=39788</id>
<updated>2007-01-02T15:08:23-08:00</updated>
<published>2007-01-02T15:08:23-08:00</published>
<summary>re: Tutorial for creating a threaded socket server and client application</summary>
<content>INDEED, if you cant see any client connected !Verify that you set the TServerSocket with option : stThreadBlocking !to test more efficiently use, netcat or telnet :)</content>
</entry>
<entry>
<title>re: Tutorial for creating a threaded socket server and client application</title>
<author>
<name>Andrei C&#226;mpeanu</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38940</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38940</id>
<updated>2006-02-23T14:37:45-08:00</updated>
<published>2006-02-23T14:37:45-08:00</published>
<summary>re: Tutorial for creating a threaded socket server and client application</summary>
<content>as far as i fgured out (bumped into it myself, and took about 2 days of my life to find out what's wrong), it's the port number that's the problem.after a long search on the inet on this error's details, one description mentiones that a &quot;port number being 0&quot; is 1 of the reasons for the this error's trigger. try setting it to 1024 or above for both the server and client sockets. most, if not all below this value are used by other services that may run on your system.this error's also triggered if the client can't connect to a server, so it can also be interpreted as either: server's not &quot;active&quot;, or it's not even being turned on.</content>
</entry>
<entry>
<title>Tutorial for creating a threaded socket server and client application</title>
<author>
<name>kuro gospodi</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=37594</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=37594</id>
<updated>2004-09-26T06:40:57-07:00</updated>
<published>2004-09-26T06:40:57-07:00</published>
<summary>Tutorial for creating a threaded socket server and client application</summary>
<content>Tell my pleas why I have error message &quot;Windows socket eror 10049,on API connect &quot;Pleas help my!</content>
</entry>
<entry>
<title>Tutorial for creating a threaded socket server and client application</title>
<author>
<name>Ricardo Vargas</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=35862</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=35862</id>
<updated>2003-12-07T16:48:58-08:00</updated>
<published>2003-12-07T16:48:58-08:00</published>
<summary>Tutorial for creating a threaded socket server and client application</summary>
<content>how can I do the same thing in Delphi?</content>
</entry>
<entry>
<title>Tutorial for creating a threaded socket server and client application using streams</title>
<author>
<name>David Geoghegan</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=33130</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=33130</id>
<updated>2002-09-17T01:26:21-07:00</updated>
<published>2002-09-17T01:26:21-07:00</published>
<summary>Tutorial for creating a threaded socket server and client application using streams</summary>
<content>Hi, Can any one help? I want to use your tutorial but want to send and recieve streams. ie copy a stream from one pc to anotherOn the Client side I have substituted this...void __fastcall TForm1::ClientSocket1Write(TObject *Sender,      TCustomWinSocket *Socket){  if (ClientSocket1-&gt;Active == true)      if (Socket-&gt;Connected == true)         Socket-&gt;SendText(&quot;This text is passed to and fro&quot;);}//--------------------------------------------------------------------With the following...void __fastcall TForm1::ClientSocket1Write(TObject *Sender,      TCustomWinSocket *Socket){  TMemoryStream* pms = new TMemoryStream();  Memo1-&gt;Lines-&gt;SaveToStream(pms);   // write Memo contents to the  if (ClientSocket1-&gt;Active == true) // stream.      if (Socket-&gt;Connected == true)         Socket-&gt;SendStream(pms); }//--------------------------------------------------------------------On the Server side Where and how do I put something like this?? Form1-&gt;Memo1-&gt;Lines-&gt;LoadFromStream(pStream);Instead ofForm1-&gt;Memo1-&gt;Lines-&gt;Add(String(&quot;(Client) &quot;) +String(buffer) ); in your code below.void __fastcall TMyServerThread::ClientExecute(void) {    // make sure connection is active    while (!Terminated &amp;&amp; ClientSocket-&gt;Connected)    {       try       {          // Now, use TWinSocketStream to read or write information          // over a blocking socket connection          TWinSocketStream *pStream = new TWinSocketStream(ClientSocket, CLIENTWAITTIME);          try          {             char buffer[BUFFERSIZE];             memset( buffer, 0, sizeof(buffer) );             // give the client 60 seconds to start writing             if (pStream-&gt;WaitForData(CLIENTWAITTIME))             {                if (pStream-&gt;Read(buffer, sizeof(buffer)) == 0)                   // (if can't read in 60 seconds) than close the connection                   ClientSocket-&gt;Close();                else                {                   // Client to Server test text                   Form1-&gt;Memo1-&gt;Lines-&gt;Add(AnsiString(&quot;(Client) &quot;) +AnsiString(buffer) );                   // Back again to Client                   pStream-&gt;Write( buffer, sizeof(buffer));                }                // ...                // Process requests here.                // ...             }             else                ClientSocket-&gt;Close();          }          __finally          {             delete pStream;         }      }      catch (...)      {         HandleException();      }   }}</content>
</entry>
<entry>
<title>re: Tutorial for creating a threaded socket server and client application</title>
<author>
<name>horst eichler</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=33024</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=33024</id>
<updated>2002-08-27T23:46:54-07:00</updated>
<published>2002-08-27T23:46:54-07:00</published>
<summary>re: Tutorial for creating a threaded socket server and client application</summary>
<content>I have the same problem!Have you found any solution?If &quot;YES&quot; send me please some information.Thank You in advance</content>
</entry>
<entry>
<title>RemotePort increments</title>
<author>
<name>Ronald Kavanagh</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=29903</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=29903</id>
<updated>2001-09-13T11:52:18-07:00</updated>
<published>2001-09-13T11:52:18-07:00</published>
<summary>RemotePort increments</summary>
<content>There is a little observation :The example works normally, but if you see the RemotePort at the server side, you'll perceive that RemotePort increments every time the client connects.Try to see it with this line of code:Form1-&gt;Memo1-&gt;Lines-&gt;Add(AnsiString(&quot;(Client)&quot;)+AnsiString(buffer)+&quot; RemotePort:&quot;+IntToStr(ClientSocket-&gt;RemotePort) );What's happen ?</content>
</entry>
<entry>
<title>re: Tutorial for creating a threaded socket server and client application</title>
<author>
<name>Richard Saul</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=28484</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=28484</id>
<updated>2001-03-30T13:09:18-07:00</updated>
<published>2001-03-30T13:09:18-07:00</published>
<summary>re: Tutorial for creating a threaded socket server and client application</summary>
<content>Philippe, I'm certainly no expert on this, but I have been looking at it and working with it a great deal lately.As far as I can tell, when you are in Thread Blocking mode, the server receives socket level events but you can't discern them within your ClientExecute thread.  Or at I haven't figured out how to discern them.I found that I could disconnect the client from the server in the server thread by calling Close(), but that the thread couldn't tell when the client had disconnected.The ClientRead and ClientWrite events are supposed to be replaced by the ClientExecute thread.  It may be that you can still discern the client disconnecting in the the ClientDisconnect event and take some appropriate action thereGood luck.Rich</content>
</entry>
<entry>
<title>Tutorial for creating a threaded socket server and client application</title>
<author>
<name>Philippe Durand</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=27957</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=27957</id>
<updated>2001-02-13T19:46:11-08:00</updated>
<published>2001-02-13T19:46:11-08:00</published>
<summary>Tutorial for creating a threaded socket server and client application</summary>
<content>I closed the client side of the connection and the server thread doesn't terminate. Why ?</content>
</entry>
</feed>
