RedneckTech Posted September 26, 2012 Share Posted September 26, 2012 is there anything i have to do in order to get a client to be able to check BACK into the server after it exits? ive tried resetting the arravy[$0][0] value back to 0 and even tried closing the socket, but after the client exits, i can not get it to come back in without starting the server program over again. Some stupid little trick i dont know about? Link to comment Share on other sites More sharing options...
FireFox Posted September 26, 2012 Share Posted September 26, 2012 Hi, ive tried resetting the arravy[$0][0] value back to 0 and even tried closing the socket What arravy are you talking about? Can you post your script/the snippet which causes the problem? Br, FireFox. Link to comment Share on other sites More sharing options...
bogQ Posted September 26, 2012 Share Posted September 26, 2012 (edited) maybe, can you geave us test code to replicate problem? edit: that FF beat my IE this time Edited September 26, 2012 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
FireFox Posted September 26, 2012 Share Posted September 26, 2012 edit: that FF beat my IE this time Not only this time... Link to comment Share on other sites More sharing options...
RedneckTech Posted September 26, 2012 Author Share Posted September 26, 2012 heres what im working with. TBH i feel like its a bit over my head. my boss saw the last thing i was working with to pull in MS Office licenses and now he wants me to write up a license server for something hes writing (w.e... hes the boss) Heres my server program. Copied then modified from here: expandcollapse popupTCPStartup() $IP = @IPAddress1 $Port = 1018 $max_connections = 500 $datafile = @WorkingDir & "records.txt" $n = 1 $Listen = TCPListen( $IP, $Port, $max_connections) If $Listen = -1 Then Exit Global $Accept Dim $Socket_Data[$max_connections + 1][3] ;add more to the second array to add data. ;(ex) 2 would have another column for data. ;you could make Usernames or ClientIP's in it... anything you want. ;Socket_data EXAMPLE ;$Socket_Data[0][0] = AMOUNT OF CURRENT CLIENTS ;$Socket_Data[1][0] = client 1 ;$Socket_Data[2][0] = client 2 ;$Socket_Data[n][0] = client n ProgressOn ('Socket Data', 'Reseting Socket Data...') For $0 = 0 To $max_connections $Socket_Data[$0][0] = 0 ;To reset the Socket array. ProgressSet (Round (($0 / $max_connections) * 100),'','Reseting Socket Data...') Sleep (10) Next ProgressOff () FileOpen($datafile, 1) While 1 _AcceptData() Sleep(100) If ProcessExists("EndLicSrv.exe") <>0 Then _Exit_() WEnd Func _AcceptData() $Accept = TCPAccept($Listen) If $Accept = -1 Then Return For $0 = 1 to $max_connections If $Socket_Data[$0][0] = 0 Then $Socket_Data[$0][0] = $Accept Do $Recv = TCPRecv( $Accept, 1000000) If ProcessExists ("EndLicSrv.exe") <> 0 Then _Exit_() Sleep(50) Until $Recv <> "" MsgBox(0,"","exited Do Loop, $Recv = " & $Recv) ;$data = _AnalyzeRecv($Recv) ;MsgBox(0,"", "$Data = " & $data) ;If $data = $Recv Then ;Else ;EndIf $exitDO = 1 While 2 $line = FileReadLine($datafile, $n) If @error = -1 Then ExitLoop If $line = $Recv Then TCPSend($Accept, "whoahwhoahwhoah, not cool brah, old news." & @CRLF & "whachu tryin'a do son?!?!") ExitLoop Sleep(650) EndIf $n = $n + 1 Wend If @Error = -1 Then FileWriteLine($datafile, $Recv) TCPSend($Accept, "s'all good brah, i got you now") EndIf $confirm = TimerInit() Do If TimerDiff($confirm) = 10000 Then ExitLoop $RecvCon = TCPRecv( $Accept, 1000000) If ProcessExists ("EndLicSrv.exe") <> 0 Then _Exit_ () Until $RecvCon <> "" $n = 1 $Socket_Data[$0][0] = 0 EndIf Next EndFunc Func _Exit_ () For $0 = 1 To $max_connections TCPCloseSocket ($Socket_Data[$0][0]) Next TCPCloseSocket ($Accept) TCPShutdown () Exit EndFunc Func _AnalyzeRecv($DataRAW) $RecvArray = StringSplit($DataRAW, "^") If $RecvArray[$RecvArray[0]] = 0 Then Return $DataRAW Else MsgBox(0, "", "analyze recv else1" & @CRLF & $RecvArray[0]) EndIf EndFunc yea i know i have some stuff commented out, but im just trying to get this to work before i worry about the other stuff. Problem is that client can check in, but cant check back in without restarting the server. Client below: #Include <Timers.au3> TCPStartup() $IP = TCPNameToIP(InputBox("what IP", "Please input the IP address you would like to send to")) $Port = 1018 For $0 = 0 To 10 $Socket = TCPConnect($IP, $Port) If $Socket <> -1 then ExitLoop TCPCloseSocket($Socket) Sleep(100) Next If $Socket = -1 Then _Exit() TCPSend($Socket, $License & " , " & @ComputerName & " , " & DriveGetSerial(@HomeDrive)) $Timeout = TimerInit() Do $Recv = TCPRecv ($Socket, 1000000) Sleep(300) If TimerDiff($Timeout) >= 30000 Then ExitLoop Until $Recv <> "" If $Recv = "" Then _Exit() _Exit () Func _Exit () TCPCloseSocket ($Socket) TCPShutdown() Exit EndFunc ;==>_Exit_ thanks guys in advance. im about shot working on this one Link to comment Share on other sites More sharing options...
RedneckTech Posted September 26, 2012 Author Share Posted September 26, 2012 i think it has to do with where im resetting the array. at the end of the for/next loop. That wasnt in there before and i was still having the problem. so the reset array/close socket at the end is not my ONLY problem (if it is a problem) just been testing with it Link to comment Share on other sites More sharing options...
RedneckTech Posted September 26, 2012 Author Share Posted September 26, 2012 oh. just realized i posted the old version of the client. just ad a tcpsend() after the main process, but before the _Exit_().. Forgot that ive been updating the client on the other computer, not this one Link to comment Share on other sites More sharing options...
FireFox Posted September 26, 2012 Share Posted September 26, 2012 oh. just realized i posted the old version of the client. just ad a tcpsend() after the main process, but before the _Exit_().. Forgot that ive been updating the client on the other computer, not this oneProblem solved ? Link to comment Share on other sites More sharing options...
bogQ Posted September 26, 2012 Share Posted September 26, 2012 (edited) if not problem solved then @ op, if your main goal is to only send data from server once the client is connected than i dont see why you need to use 2D array, well even if that isnt your plan i hardly think that you need all that mess in there Simple server #include <Array.au3> TCPStartup() Global $Socket_Data[1], $Recv Global $Listen = TCPListen(@IPAddress1, 1018, 500) If @error Then MsgBox(0,'',@error) Exit EndIf $Socket_Data[0] = 0 While 1 For $x = $Socket_Data[0] To 1 Step -1;front to bck loop cos of _ArrayDelete $Recv = TCPRecv($Socket_Data[$x], 1000000) If $Recv Then MsgBox(0, $x, "exited Do Loop, $Recv = " & $Recv,3) ;~ TCPSend($Socket_Data[$x], 'haha' );send some response if needed or additional code before closing that socket TCPCloseSocket($Socket_Data[$x]) _ArrayDelete($Socket_Data,$x) $Socket_Data[0] = $Socket_Data[0] - 1 EndIf Next _Accept() WEnd Func _Accept() $Accept = TCPAccept($Listen) If $Accept <> -1 Then MsgBox(0,'Connected',$Accept,1) _ArrayAdd($Socket_Data,$Accept) $Socket_Data[0] = $Socket_Data[0] + 1 EndIf EndFunc client #Include <Timers.au3> TCPStartup() $Socket = TCPConnect(@IPAddress1, 1018) If $socket = -1 Then Exit TCPSend($Socket, 'aasad' & " , " & @ComputerName & " , " & DriveGetSerial(@HomeDrive)) ;gona try if needed to recive last msg from server (named 'haha' in server script) before exiting ;~ Do ;~ $Recv = TCPRecv($Socket, 1000000) ;~ Until $Recv ;~ MsgBox(0,'Recived from server:',$Recv) Sleep(1000) so the server will w8 for connection and recive msg, send response to client if needed and kill socket with its array pointer after its done. so nothing 2 classy but still working and no problems on running identical client more than 1 time Edited September 26, 2012 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
RedneckTech Posted September 27, 2012 Author Share Posted September 27, 2012 @firefox - no problem wasnt solved (at that time) @bogQ - ill look into that rather than clean up mine. I realized at like 11 pm last night that the problem was i was looking at the fundamentals of the original program wrong. Once inside the main function, it just kinda waited and sat there. Added a Return at the end of the For/Next Loop and VIOLA!!! Now just need to clean up my code and test or run bog's version and test and should finally be finished! Looks like the problem was just the fact that i didnt 100% understand the code i was trying to modify and once it clicked i got it. Thanks for the code bog. ill definitely look into that one Link to comment Share on other sites More sharing options...
FireFox Posted September 27, 2012 Share Posted September 27, 2012 Looks like the problem was just the fact that i didnt 100% understand the code i was trying to modifyI knew it. It's better to make it yourself if there is not a complete UDF that fill your needs.Check this : Br, FireFox. Link to comment Share on other sites More sharing options...
RedneckTech Posted September 27, 2012 Author Share Posted September 27, 2012 I like that. It really should be added to the help file. Thanks to bogQ ive got a working server at this point. kinda gone nuts on it since i got it from him =] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now