[Gambas-user] Network Programming

John Dovey dovey.john at gmail.com
Tue May 18 09:10:09 CEST 2021


While I’m on this, I have some questions.

I created this as a separate class in my project and instantiated the class
from my main form. When I close my main form, the program doesn’t. What do
I need to do to kill the class?

Also, I’m bother by the use of “LAST”. My concept is that I was wanting to
have the server accept connections as they arrive, and then manage the full
session with the client, but the LAST is confusing me. Do I need to track
the socket object as a list of “connections”?

JD

On Mon, May 17, 2021 at 5:49 PM T Lee Davidson <t.lee.davidson at gmail.com>
wrote:

> On 5/17/21 3:19 PM, John Dovey wrote:
> > Does anyone know what happened to this page?
> > http://gambaswiki.org/wiki/tutorial/chat <
> http://gambaswiki.org/wiki/tutorial/chat>
> >
> > It seems to be exactly what I needed as a sample for something else I
> want to do.
> > Thanks
> > John
>
> I never even knew that page was there, lol. Anyway, there is example code
> at http://gambaswiki.org/wiki/doc/network#t13 that
> could likely be used as a basis for your needs. I took that code and
> reworked it a bit to make a simple chat server. I have not
> tested it so it may have (read, probably has) bugs.
>
> ' Gambas class file
> PUBLIC Clients AS Object[]
> PUBLIC Srv AS ServerSocket
>
> PUBLIC SUB FMain_Open()
>
>    Clients = NEW Object[]
>    Srv = NEW ServerSocket AS "Srv"
>    Srv.Port=3450
>    Srv.Type = Net.Internet
>    Srv.Listen()
>
> END
>
> PUBLIC SUB Srv_Connection(Host AS String)
>
>    PRINT "Accepting connection from --> " & Host
>    Clients.Add(Srv.Accept())
>
> END
>
> PUBLIC SUB Socket_Read()
>
>    DIM sCad AS String
>    READ #LAST, sCad, Lof(LAST)
>    FOR EACH oSocket as Socket in Clients
>      IF oSocket.RemoteHost = LAST.RemoteHost THEN ' Don't echo to sender
>        Continue
>      END IF
>      WRITE #oSocket, sCad, Len(sCad)
>    NEXT
>
> END
>
> PUBLIC SUB Socket_Closed()
>
>    PRINT "Connection closed"
>    Clients.Remove(Clients.Find(LAST))
>
> END
>
>
> --
> Lee
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-- 
Sent from Gmail Mobile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210518/6cd73f4b/attachment-0001.htm>


More information about the User mailing list