'############################################################################################################## #Define TSNE_SUBCALLBACK #include once "TSNE_V3.bi" '############################################################################################################## Type Client_Type V_Next as Client_Type Ptr V_Prev as Client_Type Ptr V_TSNEID as UInteger V_IPA as String V_Data as String End Type '-------------------------------------------------------------------------------------------------------------- Dim Shared G_ClientF as Client_Type Ptr Dim Shared G_ClientL as Client_Type Ptr Dim Shared G_ClientMux as Any Ptr '############################################################################################################## Sub SendToAll(V_Data as String) MutexLock(G_ClientMux) Dim TPtr as Client_Type Ptr = G_ClientF Do Until TPtr = 0 TSNE_Data_Send(TPtr->V_TSNEID, V_Data) TPtr = TPtr->V_Next Loop MutexUnLock(G_ClientMux) End Sub '############################################################################################################## Sub TSNE_Disconnected(ByVal V_TSNEID as UInteger, ByVal V_CallBackPtr as Client_Type Ptr) If V_CallBackPtr = 0 Then Exit Sub Print "[CLIENT] Disconnected: " & V_TSNEID & " " & V_CallBackPtr->V_IPA MutexLock(G_ClientMux) Dim TPtr as Client_Type Ptr = G_ClientF Do Until TPtr = 0 If TPtr = V_CallBackPtr Then If TPtr->V_Next <> 0 Then TPtr->V_Next->V_Prev = TPtr->V_Prev If TPtr->V_Prev <> 0 Then TPtr->V_Prev->V_Next = TPtr->V_Next If G_ClientF = TPtr Then G_ClientF = TPtr->V_Next If G_ClientL = TPtr Then G_ClientL = TPtr->V_Prev Exit Do End If TPtr = TPtr->V_Next Loop MutexUnLock(G_ClientMux) DeAllocate(V_CallBackPtr) End Sub '############################################################################################################## Sub TSNE_Connected(ByVal V_TSNEID as UInteger, ByVal V_CallBackPtr as Client_Type Ptr) If V_CallBackPtr = 0 Then TSNE_Disconnect(V_TSNEID): Exit Sub Print "[CLIENT] Connected: " & V_TSNEID & " " & V_CallBackPtr->V_IPA End Sub '############################################################################################################## Sub TSNE_NewData(ByVal V_TSNEID as UInteger, ByRef V_Data as String, ByVal V_CallBackPtr as Client_Type Ptr) If V_CallBackPtr = 0 Then TSNE_Disconnect(V_TSNEID): Exit Sub With *V_CallBackPtr .V_Data += V_Data Print "[CLIENT] DATA: " & V_TSNEID & " " & .V_IPA & " DataLen:"; Len(.V_Data) 'Nur zu dem clienten senden, vond em wir daten empfangen haben TSNE_Data_Send(V_TSNEID, "Habe daten von dir empfangen!") 'zu allen clienten senden SendToAll("Hab von " & .V_IPA & " datenempfangen!") .V_Data = "" End With End Sub '############################################################################################################## Sub TSNE_NewConnection(ByVal V_TSNEID as UInteger, ByVal V_RequestID as Socket, ByVal V_IPA as String) Dim TNewTSNEID as UInteger Dim TClient as Client_Type Ptr = CAllocate(SizeOf(Client_Type)) TClient->V_IPA = V_IPA MutexLock(G_ClientMux) Dim RV as Integer = TSNE_Create_Accept(V_RequestID, TNewTSNEID, , @TSNE_Disconnected, @TSNE_Connected, @TSNE_NewData, , , , Cast(Any Ptr, TClient)) If RV <> TSNE_Const_NoError Then DeAllocate(TClient) Print "[CLIENT] [FEHLER] " & TSNE_GetGURUCode(RV) Exit Sub End If If G_ClientL <> 0 Then G_ClientL->V_Next = TClient G_ClientL->V_Next->V_Prev = G_ClientL G_ClientL = G_ClientL->V_Next Else G_ClientL = TClient G_ClientF = G_ClientL End If With *G_ClientL .V_TSNEID = TNewTSNEID .V_IPA = V_IPA End With MutexUnLock(G_ClientMux) Print "[CLIENT] New Connect: " & TNewTSNEID & " " & V_IPA End Sub '############################################################################################################## G_ClientMux = MutexCreate() Dim TServerID as UInteger Dim RV as Integer = TSNE_Create_Server(TServerID, 1234, 10, @TSNE_NewConnection) If RV <> TSNE_Const_NoError Then Print "[SERVER] [FEHLER] " & TSNE_GetGURUCode(RV) End 0 End if Print "[SERVER] OK!" Do Sleep 10, 1 Loop until InKey() = Chr(27) RV = TSNE_Disconnect(TServerID) TSNE_WaitClose(TServerID) MutexDestroy(G_ClientMux) End 0