fb:porticula NoPaste
server.bas
Uploader: | ThePuppetMaster |
Datum/Zeit: | 12.12.2007 02:47:20 |
#include "TSNE.bi"
Dim G_Server as Integer
Dim Shared G_ClientD() as Integer
Dim Shared G_ClientC as Integer
Dim BV as Long
Declare Sub TSNE_Disconnected (ByVal V_TSNEID as Integer)
Declare Sub TSNE_Connected (ByVal V_TSNEID as Integer)
Declare Sub TSNE_NewConnection (ByVal V_TSNEID as Integer, ByVal V_RequestID as Socket)
Declare Sub TSNE_NewData (ByVal V_TSNEID as Integer, ByRef V_Data as String)
Print "[INIT] Setup..."
TSNE_Event_Set(@TSNE_Disconnected, @TSNE_Connected, @TSNE_NewConnection, @TSNE_NewData)
Print "[INIT] Client..."
BV = TSNE_Create_Server(G_Server, 1234, 10)
If BV = 0 Then
Print "[OK]"
Else: Print "[FEHLER] " & TSNE_GetGURUCode(BV)
End if
Print "[WAIT] ..."
TSNE_WaitClose(G_Server)
Print "[WAIT] OK"
Print "[END]"
end
Sub TSNE_Disconnected (ByVal V_TSNEID as Integer)
Print "[DIS] >" & V_TSNEID & "<"
Dim X as Long
For X = 1 to G_ClientC
If G_ClientD(X) > 0 Then
G_ClientD(X) = 0
Exit For
End If
Next
End Sub
Sub TSNE_Connected (ByVal V_TSNEID as Integer)
Print "[CON] >" & V_TSNEID & "<"
End Sub
Sub TSNE_NewConnection (ByVal V_TSNEID as Integer, ByVal V_RequestID as Socket)
Print "[NCO] >" & V_TSNEID & "<___>" & V_RequestID & "<"
Dim X as Long
Dim T as String
For X = 1 to G_ClientC
If G_ClientD(X) = 0 Then
TSNE_Create_Accept(V_RequestID, G_ClientD(X), 0, T)
G_ClientD(X) = V_TSNEID
Print "[_OK] >" & V_TSNEID & "<___>" & G_ClientC & "< - " & T
Exit Sub
End If
Next
G_ClientC += 1
Redim Preserve G_ClientD(G_ClientC) as Integer
TSNE_Create_Accept(V_RequestID, G_ClientD(G_ClientC), 0, T)
G_ClientD(G_ClientC) = V_TSNEID
Print "[-OK] >" & V_TSNEID & "<___>" & G_ClientC & "< - " & T
End Sub
Sub TSNE_NewData (ByVal V_TSNEID as Integer, ByRef V_Data as String)
Print "[NDA] >" & V_TSNEID & "<___>" & V_Data & "<"
Dim CRLF as String
CRLF = Chr(13) & Chr(10)
If InStr(1, V_Data, CRLF & CRLF) > 0 Then
Dim D as String
D = "<html><head><title>blub</title></head><body>TSNE-Test-Server: OK</body></html>"
TSNE_Data_Send(V_TSNEID, "HTTP/1.1 200 OK" & CRLF & "connection: close" & CRLF & CRLF & D)
TSNE_Disconnect(V_TSNEID)
End If
End Sub