[Gambas-user] Network Programming

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


This is fantastic. If you don’t mind, I’ll take this and work on it a bit
more and maybe write up that chat server how to.
All the best
John

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/5fd2d328/attachment.htm>


More information about the User mailing list