[Gambas-user] Network Programming
T Lee Davidson
t.lee.davidson at gmail.com
Tue May 18 23:39:54 CEST 2021
On 5/18/21 10:43 AM, John Dovey wrote:
> Perfect. I changed my Form_Close() to include the lines
> If Server Then ' From: Static Server As ClsServer
> End If
> That works perfectly.
Just FYI, doing it that way breaks the principle of encapsulation. Suppose you change the variable name of the SocketServer in
your Server class and forget to change it in your main Form. You then just created a bug for yourself.
Perhaps consider creating a Close subroutine in your Server class the executes Srv.Close(). Then, you have only one file in
which the variable name needs to be kept consistent. The call to Close in your main form would then be, simply, "Server.Close()".
> I'm not quite sure what would be "necessary". That's what I'm trying to figure out. One aspect of where I'm heading is to have
> the server accept a remote connection, then spawn off a brand new form which will echo locally what is happening on the remote.
> The idea I have here, and I'm really stumbling in the dark, is I'd like to have a client-server setup where I can generate cairo
> commands on the server and send them to the remote client where they would be rendered. I want to also render them locally so
> that I can send (on the client's request) an SVG/PNG/PDF version of what's been rendered. I did something similar many years ago
> using Winsock connections, but there I had to maintain my own in-memory table of connections etc.
You may wish to take a look at the ServerSocket example in the Gambas Farm. It uses the Socket's Tag property to keep track of
data unique to each client and respond accordingly. Forms also have a Tag property. You might be able to use either Socket.Tag
or Form.Tag to associate a socket with a form.
More information about the User