[Gambas-user] Network Programming

T Lee Davidson t.lee.davidson at gmail.com
Tue May 18 00:48:28 CEST 2021


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


More information about the User mailing list