fb:porticula NoPaste
PNE :: examples/telnet_serv.bas
Uploader: | PMedia |
Datum/Zeit: | 05.12.2007 15:05:39 |
''==============================================================================
''
'' PMedia's Network Engine
'' for FreeBASIC
''
''==============================================================================
'
' telnet_serv.bas =-------------------------------------------------------------
'
' this should show you how to create an server with PNE
' AND YES, I KNOW THAT THAT ISN'T RFC-CONFORM ;D
#include "pne/pne.bi"
Declare sub onNewClient(slotid as uinteger)
Declare sub onClientLost(slotid as uinteger)
Declare sub onReceive(slotid as uinteger, message as string)
Declare Sub onError()
dim shared as pne.Server TelNetServ
TelnetServ.startServer(23, 2)
TelnetServ.bindEvent(pne.e_onNewClient, @onNewClient)
TelnetServ.bindEvent(pne.e_onClientLost, @onClientLost)
TelnetServ.bindEvent(pne.e_onReceive, @onReceive)
TelnetServ.bindEvent(pne.e_onError, @onError)
Do
sleep 5
Loop Until MultiKey(&h01) or inkey = chr(255)+"k"
TelnetServ.stopServer()
End
'===============================================================================
sub onNewClient(slotid as uinteger)
Print "New client at slot :" + str(slotid)
print "IP :" + TelnetServ.SlotIPs(slotid)
End Sub
sub onClientLost(slotid as uinteger)
Print "Client disconnected :" + str(slotid)
print "IP :" + TelnetServ.SlotIPs(slotid)
End Sub
Sub onReceive(Slotid As UInteger, Message as String)
Print "Message from IP " + TelnetServ.SlotIPs(slotid)
End Sub
Sub onError()
Print "Error happened"
Print TelnetServ.GetLastError("EN")
End Sub