fb:porticula NoPaste
Server.bas
Uploader: | ThePuppetMaster |
Datum/Zeit: | 06.12.2007 12:35:40 |
#include "TSNE.bi"
Dim G_Server as TSNE_Socket
Dim Shared G_ClientD() as TSNE_Socket
Dim Shared G_ClientC as Long
Dim BV as Long
Declare Sub TSNE_Disconnected (ByRef V_Socket as TSNE_Socket)
Declare Sub TSNE_Connected (ByRef V_Socket as TSNE_Socket)
Declare Sub TSNE_NewConnection (ByRef V_Socket as TSNE_Socket, ByRef V_RequestID as Socket)
Declare Sub TSNE_NewData (ByRef V_Socket as TSNE_Socket, ByRef V_Data as String)
Declare Sub TSNE_SendSuccess (ByRef V_Socket as TSNE_Socket, ByRef V_Bytes as Long)
Print "[INIT] Setup..."
TSNE_Event_Set(@TSNE_Disconnected, @TSNE_Connected, @TSNE_NewConnection, @TSNE_NewData, @TSNE_SendSuccess)
Print "[INIT] Client..."
BV = TSNE_Create_Server(G_Server, 1234, 10 , 0)
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 (ByRef V_Socket as TSNE_Socket)
Print "[DIS]"
End Sub
Sub TSNE_Connected (ByRef V_Socket as TSNE_Socket)
Print "[CON]"
Dim CRLF as String
CRLF = Chr(13) & Chr(10)
TSNE_Data_Send(V_Socket, "HTTP/1.1 200 OK" & CRLF & "connection: close" & CRLF & CRLF & "TSNE-Test-Server: OK")
Dim X as Long
For X = 1 to G_ClientC
If G_ClientD(X).T_InUse = 1 Then
If G_ClientD(X).V_Socket = V_Socket.V_Socket Then
TSNE_Disconnect(V_Socket)
G_ClientD(X).T_InUse = 0
Exit For
End If
End If
Next
End Sub
Sub TSNE_NewConnection (ByRef V_Socket as TSNE_Socket, ByRef V_RequestID as Socket)
Print "[NCO] >" & V_RequestID & "<"
Dim X as Long
For X = 1 to G_ClientC
If G_ClientD(X).T_InUse = 0 Then
TSNE_Create_Accept(V_RequestID, G_ClientD(X))
G_ClientD(X).T_InUse = 1
Print "[NCO] OK:" & G_ClientC
Exit Sub
End If
Next
G_ClientC += 1
Redim Preserve G_ClientD(G_ClientC) as TSNE_Socket
TSNE_Create_Accept(V_RequestID, G_ClientD(G_ClientC))
G_ClientD(G_ClientC).T_InUse = 1
Print "[NCO] NK:" & G_ClientC
End Sub
Sub TSNE_NewData (ByRef V_Socket as TSNE_Socket, ByRef V_Data as String)
Print "[NDA]: >" & V_Data & "<"
End Sub
Sub TSNE_SendSuccess (ByRef V_Socket as TSNE_Socket, ByRef V_Bytes as Long)
Print "[SES]"
End Sub