RAD Studio
ContentsIndex
PreviousUpNext
Reading and writing over socket connections
Name 
Description 
When the connection is blocking, your socket must initiate reading or writing over the connection. It cannot wait passively for a notification from the socket connection. Use a blocking socket when your end of the connection is in charge of when reading and writing takes place.
For client or server sockets, set the BlockMode property to bmBlocking to form a blocking connection. Depending on what else your client application does, you may want to create a new execution thread for reading or writing, so that your application can continue executing code on other threads while it waits for the reading... more 
Non-blocking connections read and write asynchronously, so that the transfer of data does not block the execution of other code in you network application. To create a non-blocking connection for client or server sockets, set the BlockMode property to bmNonBlocking.
When the connection is non-blocking, reading and writing events inform your socket when the socket on the other end of the connection tries to read or write information. 
Non-blocking sockets generate reading and writing events when they need to read or write over the connection. You can respond to these notifications in an OnReceive or OnSend event handler.
The socket object associated with the socket connection is provided as a parameter to the read or write event handlers. This socket object provides a number of methods to allow you to read or write over the connection.
To read from the socket connection, use the ReceiveBuf or Receiveln method. To write to the socket connection, use the SendBuf, SendStream, or Sendln. 
The reason you form socket connections to other machines is so that you can read or write information over those connections. What information you read or write, or when you read it or write it, depends on the service associated with the socket connection.
Reading and writing over sockets can occur asynchronously, so that it does not block the execution of other code in your network application. This is called a non-blocking connection. You can also form blocking connections, where your application waits for the reading or writing to be completed before executing the next line of code.... more 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!