Sign in to follow this  
Followers 0
Tam0r

Problem With Tcpip

1 post in this topic

hi.

I've written a server module which checks if clients are connected. If connecting via hyperterminal and sending 2 the server shows the client online. Usually when closing the connection properly the client sends 1 to the server, so the server knows the client is offline. But if the connection is terminated for some reason (e.g. internet connection is lost) the client can't logoff from the server and the server shows this client online, although it is not.

I've tried to fix this problem with this code:

elseif $err[$i] <> 0 Then
        $ConnectedSocket[$i] = -1
        if $user = 0 Then
            Else
        $user = $user -1
    $Client[$i] = "0"
    $iptext[$i] = "000.000.000.000" 
    $err[$i] = "0"

Is there something wrong with the code, or is there a better (operative) way to say the server, that the client is offline?

Here's the programs INI followed by the program itself. Sorry for the grubby code, its still in the developing phase. :)

(You can use one of this ports, if you want to try it with the hyperterminal)

cash.ini

[Werte]
User=20
Port=5022



[Port]
0 = 1085
1 = 5015
2 = 5016
3 = 5017
4 = 5018
5 = 5019
6 = 5020
7 = 5021
8 = 5022
9 = 5023
10 = 5024
11 = 5025
12 = 5026
13 = 5027
14 = 5028
15 = 5029
16 = 5030
17 = 5031
18 = 5032
19 = 5033
20 = 5034
[User]
rizla=F58DA52FBABE7A97CC3C608E84A41638F5AA38191B8ADEA04ABD2A59B183A03EED3B4FBA|5016
tam0r=F58DA553BABE7D92CC3C61FB84A4163EF5AA3F601B8AA0A74ABC2F59B183A03F|5015
Veljo=F588A555BABB7A97CC4661FB84A51639F5AA3F621B89DEA14AB92A58|5017
zafer=F588A555BABB7A97CC4660FA84A46A39F5AB38601CFBA0D4|5018
cihad=F58DDB52BABB7A93CC4660FD84A4163AF5AB38171B8ADEDB4ABC2A58B6F7A042ED3B4FBA|5019
admin=F588DB20BABB7A93CC3861FB84D8163BF5AA38651B8ADEA04AB92A20B183A038ED3F4FBA|5020
darkest=F58DDB20BABB7A93CC3C61FA84A46A3FF5AA3F621B89DEA64ABD2A24B183A03E|5021

program code

#include <file.au3>
#include <GuiEdit.au3>
#include <GUIConstants.au3>
#include <string.au3>
#include <Date.au3>

Opt("TrayIconDebug", 1)

Global $CV = IniRead (@ScriptDir&"/Cash.ini", "Werte", "User", "20" )
Global $CP = IniReadSection (@ScriptDir&"/Cash.ini", "Port"  )

$Anfangszeit = TimerInit()
$anfangszeit2 = _TimeToTicks($Anfangszeit)

TCPStartUp()
$ver = "2.0.2"

$IP = @IPAddress1


Dim $Vernr[$CV+1]
Dim $iptext[$CV+1]
Dim $client[$CV+1]
Dim $MainSocket[$CV+1]
Dim $ConnectedSocket[$CV+1]
Dim $RogueSocket[$CV+1]
Dim $input[$CV+1]
Dim $err[$CV+1]
Dim $result[$CV+1]

Global $iSec, $iMin, $iHour, $iTime

$adminon = 0
$user = 0
$selbs = 0
$Masteruser = 0
$Adminnr = 0
$masternr = 0

Global $MainSockets0, $ConnectedSockets0 = -1
Global $Mainauth, $Connectedauth = -1
Global $MainSocket1, $ConnectedSocket1 = -1
Global $MainSocket2, $ConnectedSocket2 = -1
Global $MainSocket3, $ConnectedSocket3 = -1
Global $MainSocket4, $ConnectedSocket4 = -1
Global $MainSocket5, $ConnectedSocket5 = -1
Global $MainSocket6, $ConnectedSocket6 = -1
Global $MainSocket7, $ConnectedSocket7 = -1
Global $MainSocket8, $ConnectedSocket8 = -1
Global $MainSocket9, $ConnectedSocket9 = -1
Global $MainSocket10, $ConnectedSocket10 = -1
Global $MainSocket11, $ConnectedSocket11 = -1
Global $MainSocket12, $ConnectedSocket12 = -1
Global $MainSocket13, $ConnectedSocket13 = -1
Global $MainSocket14, $ConnectedSocket14 = -1
Global $MainSocket15, $ConnectedSocket15 = -1
Global $MainSocket16, $ConnectedSocket16 = -1
Global $MainSocket17, $ConnectedSocket17 = -1
Global $MainSocket18, $ConnectedSocket18 = -1
Global $MainSocket19, $ConnectedSocket19 = -1
Global $MainSocket20, $ConnectedSocket20 = -1

For $i = 1 to $CV step +1
    $Vernr[$i] = "x.x.x"
    $iptext[$i] = "000.000.000.000"
    $client[$i] = 0
    $MainSocket[$i] = TCPListen($IP, $CP[$i+1][1],  100 )
    $RogueSocket[$i] = -1         
Next
$RogueSockets0 = -1
$Rogueauth = -1
$MainSockets0 = TCPListen($IP, $CP[1][1],  100 )
$Mainauth = TCPListen($IP, 1050,  100 )


HotKeySet ( "{F7}" , "_Exit" )

$tcp = GUICreate (" Debug",450,200,0,0)
$tcpedit = GUICtrlCreateEdit ("", 10,10,350,150)
GUISetState(@SW_show, $tcp)


While 1
    
;Auswertung der Empfangenen Daten von Client Auth
if $Connectedauth = -1 Then
    Global $Connectedauth = TCPAccept($Mainauth)
Else

    $Rogueauth = TCPAccept($Mainauth)
    $inputauth = TCPRecv($Connectedauth,10240)
    $errauth = @error 
    $resultauth = StringLeft($inputauth,1)
    
    $string = StringLen ( $inputauth )
    
if $string = 0 then
    Else
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "<----- A  "&@HOUR&":"&@MIN&":"&@SEC&"       "&$inputauth&@CRLF&$tcpread)
EndIf
    
    if $resultauth = "1" Then
        _auth()

    elseif  $errauth <> 0 Then
        $Connectedauth = -1
    EndIf
    


EndIf

    
















For $i = 1 to $CV step +1
    
;Auswertung der Empfangenen Daten von all Client 
if $ConnectedSocket[$i] = -1 Then
    $ConnectedSocket[$i] = TCPAccept($MainSocket[$i])
Else

    $RogueSocket[$i] = TCPAccept($MainSocket[$i])
    $input[$i] = TCPRecv($ConnectedSocket[$i],10240)
    $err[$i] = @error 
    $result[$i] = StringLeft($input[$i],1)
    
    $string = StringLen ( $input[$i] )
    $string2 = StringSplit ( $input[$i], "|" )
if $string = 0 then
    Else
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "<----- "&$i&"  "&@HOUR&":"&@MIN&":"&@SEC&"      "&$input[$i]&@CRLF&$tcpread)

EndIf
    
    if $result[$i] = "1" Then
        _offline1()
    ElseIf $result[$i] = "2" Then
        _online1()
    ElseIf $result[$i] = "3" Then
        _ip1()


        
    elseif $err[$i] <> 0 Then
        $ConnectedSocket[$i] = -1
        if $user = 0 Then
            Else
        $user = $user -1
    $Client[$i] = "0"
    $iptext[$i] = "000.000.000.000" 
    $err[$i] = "0"
EndIf

    EndIf
    

EndIf

Next


sleep (100)
WEnd

















Func _Exit()
    sleep (500)
    TCPCloseSocket($Connectedauth)
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "-----> "&$i&"  "&@HOUR&":"&@MIN&":"&@SEC&"      Close TCP/Auth"&@CRLF&$tcpread)
    sleep(100)
    For $i = 0 to $cv step +1
    TCPSend( $ConnectedSocket[$i], "10000")
    TCPCloseSocket($ConnectedSocket[$i])
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "-----> "&$i&"  "&@HOUR&":"&@MIN&":"&@SEC&"      10000"&@CRLF&$tcpread)
    sleep (100)
    Next
    splashTextOn("", @CRLF&@CRLF&"Z-Server Close", 130, 100, -1, -1, 1, "", "0" )
    Sleep(1000)
    Exit
EndFunc

    
Func _online1()
    $vernr[$i] = StringTrimLeft ( $input[$i], 5 )
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "-----> "&$i&"  "&@HOUR&":"&@MIN&":"&@SEC&"      20000"&@CRLF&$tcpread)
    TCPSend( $ConnectedSocket[$i], "20000")
    sleep(50)
    $z = $i *10
    $z = 20000 + $z
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "-----> 0  "&@HOUR&":"&@MIN&":"&@SEC&"       "&$z&$vernr[$i]&@CRLF&$tcpread)
    TCPSend( $ConnectedSockets0, $z&$vernr[$i])
    $Client[$i] = "1"
    $user = $user +1

EndFunc 


Func _offline1()
    $z = $i *10
    $z = 10000 + $z
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "-----> 0  "&@HOUR&":"&@MIN&":"&@SEC&"       "&$z&@CRLF&$tcpread)    
    TCPSend( $ConnectedSockets0, $z)
    $ConnectedSocket[$i] = -1
    $Client[$i] = "0"
    $iptext[$i] = "000.000.000.000" 
    global $user = $user -1 
EndFunc


Func _auth()
    
    $Benutzername = StringSplit ( $inputauth, "|" )
    $Passwordread = IniRead (@ScriptDir&"/Cash.ini", "User", $Benutzername[2], "Error" )
    $split = StringSplit ( $Passwordread, "|" ) 
    if $Benutzername[3] = $split[1] then
        TCPSend( $Connectedauth, "A568BD95483ZCJH6248W596P|"&$split[2])
        $Connectedauth = -1
    Else
        TCPSend( $Connectedauth, "0")
        $Connectedauth = -1
    EndIf
EndFunc


Func _ip1()
    $iptext[$i] = StringTrimLeft ( $input[$i], 5 )
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "-----> "&$i&"  "&@HOUR&":"&@MIN&":"&@SEC&"      40000"&@CRLF&$tcpread)  
    $ret = TCPSend( $ConnectedSocket[$i], "40000|"&$client[1]&"|"&$client[2]&"|"&$client[3]&"|"&$client[4]&"|"&$client[5]&"|"&$client[6]&"|"&$client[7]&"|"&$client[8])
    $z = $i * 10
    $z = 30000 + $z
    $tcpread = GUICtrlRead ($tcpedit)
    GUICtrlSetData ( $tcpedit, "-----> 0  "&@HOUR&":"&@MIN&":"&@SEC&"       "&$z&@CRLF&$tcpread)    
    TCPSend( $ConnectedSockets0, $z&$iptext[$i])

EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0