Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2015 12:59
Show Gist options
  • Save anonymous/6bc31b7baf0cabfe380b to your computer and use it in GitHub Desktop.
Save anonymous/6bc31b7baf0cabfe380b to your computer and use it in GitHub Desktop.
' Gambas class file
Public Const DefaultPort As Integer = 2100
Private ServerTCP As ServerSocket ' для принятия новых соединений
Private NewSocket As Socket '
Private PoolSocet As New Socket[]
Private TimeConnect As Single
Public Port As Integer
Public Sub _new()
Port = DefaultPort
End
Public Sub Listen(Optional MaxConn As Integer = 0)
'Port = 19000
If ServerTCP = Null Then
'Сокет пустой
Else
'Сокет не пустой
ServerTCP.Close ' закрыть таки
ServerTCP = Null ' уничтожить
Endif
ServerTCP = New ServerSocket ' создать сокет
Object.Attach(ServerTCP, Me, "ServerTCP") ' присвоить имя для принятия событий
ServerTCP.Port = Port ' установить порт для прослушивания
ServerTCP.Listen(MaxConn) ' начать слушать
End
Public Sub DoEvents(s As Single)
' Рекомендую для linux значение s = 0.02
Do
Wait s
Loop
End
Public Sub ServerTCP_Connection(RemoteHostIP As String)
Dim t As Single
'If TimeConnect = 0 Then TimeConnect = Timer
'If ServerTCP.Count > 40 Then Print Str(Timer - TimeConnect)
Print "Соединение принято " & Str(ServerTCP.Count)
t = Timer
NewSocket = ServerTCP.Accept()
Print Str(Timer - t)
'Print "RemotePort " & Str(NewSocket.RemotePort)
'Print "LocalPort " & Str(NewSocket.LocalPort)
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment