Thanks,
Dan English
Realsoft Development
Paul
Paul Gertzen <pger...@livetechnology.com> wrote in message
news:8348hg$fq...@forums.borland.com...
> As I said in my previous post, the onclientread and onclientwrite events
are
> for a non-blocking TServerSocket. The example I sent you uses a
> thread-blocking server (servertype=stthreadblocking). I suggest you use
the
> same method as my example. to send data back to the client within the
> onClientExecute method, do the following:
>
> procedure TClientThread.ClientExecute;
> Type THeader = record
> datasize : integer;
> message : shortstring; // you CANNOT use string as it is
> dynamic!!!!
> End;
> var SendBuffer : PChar;
> MyHeader : THeader;
> begin
> while not Terminated and ClientSocket.Connected do
> try
> ... read the data as per my example
> ... once all data has been read and processed, write back to the
client
> as follows
> ... assume you want to send a record back (THeader)
> GetMem(SendBuffer, SizeOf(THeader));
> MyHeader.DataSize := 0; // there is no data appended to the
header
> at this stage
> MyHeader.Message := 'This is a message from the server!!';
> // Move the header into the buffer
> Move(MyHeader, SendBuffer, SizeOf(THeader));
> BytesSent := 0;
> While (ClientSocket.Socket.Connected) And (BytesSent <>
> SizeOfDataToSend) Do
> Begin
> BytesSent := BytesSent +
> ClientSocket.Socket.SendBuf(Buffer[BytesSent],
SizeOfDataToSend-BytesSent);
> End;
> ClientSocket.Close;
> except
> end;
> end;
>
> The above is pseudo-code, not everything is there but what you need.
>
> Paul
>
> Dan English <d...@realsoftdev.com> wrote in message
> news:833qb5$c5...@forums.borland.com...
All the OnClientXXX events are invoked by winsock when an event occurs, this
is the nature of nonblocking sockets, they are event driven, here is the
sequence of the events:
(eg onClientConnect), from within that event, you need to read data into a
buffer for the client (receivebuf), the OnClientRead event will be invoked
until all the data has been read (calling receivebuf each time). you then
need to send to the client (sendbuf) once you are happy you have received
all the data, the onclientwrite event will be invoked if not all the data
was sent (where you will need to call sendbuf again).
I suggest you use the threadblocking servertype as this is easier to code,
easier to control, connection timeouts can be set (using TWinSocketStream)
unlike nonblocking sockets which cannot, you have no way of knowing what the
client is going to do next, making it difficult to free resources. I'm sure
the winshoes guys would agree with me.
Paul
Paul Gertzen <pger...@livetechnology.com> wrote in message
news:8348hg$fq...@forums.borland.com...
--
Dan English
Realsoft Development
d...@realsoftdev.com