fb:porticula NoPaste
PNEsmpl.bas - Beispielprogramm zur PNE
Uploader: | PMedia |
Datum/Zeit: | 03.12.2007 21:16:49 |
'' PNE - PMedia's Networking Engine :: TelNet-Server example
''
'' Go to http://pmedia.max06.de for other (maybe stupid?) things of him
''
#include "PNE.bi"
Declare Sub OnConnect(ConData As pneConData)
Declare Sub OnIncoming(Message As String, ConData As pneConData)
Declare Sub OnDisconnect(ConData As pneConData)
Dim Terminal As pneServer
'' Creating the Server-Handler
'' (LINUX-IMPORTANT:: Change the port-number or run program as root!)
pneCreateServer(Terminal, 23, 10)
'' Bind the event "connect" to our connect-sub, other events, too.
pneBindEvent(Terminal, pneOnConnect, @OnConnect)
pneBindEvent(Terminal, pneOnIncoming, @OnIncoming)
pneBindEvent(Terminal, pneOnDisConnect, @OnDisconnect)
'' Will terminate Server at all issues
pneErrorLevel(All)
'' Status
Print "[ ok ] Server started and ready for client connections"
''========================================================================
'' Main-Loop
''========================================================================
Do
Sleep 10
Loop Until MultiKey(&h01) Or Inkey = Chr(255) + "k"
'' Kills all Client connects violently
pneDestroyServer(Terminal)
End
''========================================================================
'' onConnect
''========================================================================
Sub OnConnect(ConData As pneConData)
'' Shows Client-IP on Screen
print "[conn] New Client: " + pneGetIP_s(ConData)
'' He is enough for us to send a welcome message
pneSendString(ConData, "Welcome to PNE Testserver")
End Sub
''========================================================================
'' onIncoming
''========================================================================
Sub OnIncoming(Message As String, ConData As pneConData)
'' Shows incoming Data:
print "[ in ] By Client: " + pneGetIP_s(ConData)
Print " Message: " + Message
'' Answer
pneSendString(ConData, "I am sorry to tell you, that this server currently no commands support :(")
End Sub
''========================================================================
'' onDisConnect
''========================================================================
Sub OnDisconnect(ConData As pneConData)
'' Shows Client-IP on Screen
print "[disc] Client disconnected " + pneGetIP_s(ConData)
End Sub