[Gambas-user] best way to use the stream from server socket?

PICCORO McKAY Lenz mckaygerhard at gmail.com
Mon Oct 14 20:07:56 CEST 2019


El lun., 14 de oct. de 2019 a la(s) 12:08, gen braga
(genbraga1 at gmail.com) escribió:
>
> Try this simple example.
> I'm using UDP as it seems to me it's enough for what you need.

Great ... thanks ! was perfect!

>
> server side:
>
> -----8<--------------------------
> Private $ServerSocket As New UdpSocket As "ServerSocket"
>
> Public Sub Main()
>
>   $ServerSocket.Port = "9876"
>   $ServerSocket.Host = "127.0.0.1"
>   $ServerSocket.Bind()
>
>   If $ServerSocket.Status < Net.Active Then Stop
>
> End
>
> Public Sub ServerSocket_Read()
>   Dim Command As Byte
>   Dim Parameter1 As Integer
>   Dim Parameter2 As String
>   Dim Parameter3 As Boolean
>
>   Command = Read #$ServerSocket As Byte
>   Parameter1 = Read #$ServerSocket As Integer
>   Parameter2 = Read #$ServerSocket As String
>   Parameter3 = Read #$ServerSocket As Boolean
>
>   Print Command
>   Print Parameter1
>   Print Parameter2
>   Print Parameter3
>
> End
> -----8<--------------------------
>
> client side:
>
> -----8<--------------------------
> Private $ClientSocket As New UdpSocket
>
> Public Sub Main()
>
>   Dim Command As Byte = 10
>   Dim Parameter1 As Integer = 1000
>   Dim Parameter2 As String = "Parameter"
>   Dim Parameter3 As Boolean = True
>
>   $ClientSocket.TargetHost = "127.0.0.1"
>   $ClientSocket.TargetPort = "9876"
>   $ClientSocket.Bind()
>
>   If $ClientSocket.Status < Net.Active Then Stop
>
>   $ClientSocket.Begin
>     Write #$ClientSocket, Command As Byte
>     Write #$ClientSocket, Parameter1 As Integer
>     Write #$ClientSocket, Parameter2 As String
>     Write #$ClientSocket, Parameter3 As Boolean
>   $ClientSocket.Send
>
>   $ClientSocket.Close()
> End
> -----8<--------------------------
>
> There are better ways to do the same but for now I think this is
> enough, as you said ur under pressure.
>
> -
> Regards,
>
> 2019-10-14 12:06 GMT-03:00, PICCORO McKAY Lenz <mckaygerhard at gmail.com>:
> > I'd like a better explanation of how I could separate what I take out
> > of the flow from the object that receives the flow on the socket
> > server.
> >
> > sorry i'm pretty late now in gambas.. due i have been busy I'm pretty
> > rusty on programming now and I'm under pressure...
> >
> > i have that piece of code but i¿m not using events in that class:
> >
> > Public Clients As Object[]
> > Public Srv As ServerSocket
> >
> > Public Sub Socket_Read()
> >
> >   Dim sCad As String
> >   Read #Last, sCad, Lof(Last)
> >   Print "Comando recibido --> " & sCad
> >   Write #Last, "Comando recibido...", 19
> >                '1234567890123456789
> > End
> >
> > (lest assume _new, _close and connect Sub's)
> >
> > i have a main module.. if i have too many impelmentations of that
> > class maybe the stream object will be very stressed.. so how to
> > property implement?
> >
> > Lenz McKAY Gerardo (PICCORO)
> > http://qgqlochekone.blogspot.com
> >
> > ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
> >
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----


More information about the User mailing list