Previous Next Edit Rename Undo Search Administration
implements a socket client to allow your programs to connect with socket servers. TCP and Local (Unix sockets) connections are implemented.
This class performs its work asynchronously, so the program will not be stopped while connecting, sending or receiving data.
This class is derived from the class Stream
, so you can use standard Stream & Input/Output functions
to send and receive data, and to close the socket.
Sockets can be used if the library "gb.net" is included in the project.
To include this library use the menu [Project] [Properties] [Components] tick the component
' Gambas class file
PUBLIC MySock AS Socket
PUBLIC SUB Button1_Click()
DIM sBuf AS String
MySock = NEW Socket
DO WHILE (MySock.Status <> 7) AND (MySock.Status > 0)
IF MySock.Status <> 7 THEN
sBuf = "Hello over there.\n"
WRITE #MySock, sBuf, Len(sBuf)
DO WHILE Lof(MySock) = 0
READ #MySock, sBuf, Lof(MySock)
Remarks for this Example
- Even though polling is shown here, you should really use callbacks to react on different states.
- See Network Programming, the tutorial about the usage of networking. There are comments to each line of this example.
- There is another example in the distribution under Networking ClientSocket.