Alexxander Posted October 5, 2013 Share Posted October 5, 2013 Hi all i had posted before my first try (which was terrible) that must detect if the other side is online or not i'm trying to make a script that i can know if the other PC is connected to the internet or not here's my second try sender TCPStartup() $TCPcon = TCPConnect (@IPAddress1, 1234) TCPSend($TCPcon, "on") receiver #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Form1", 615, 227) $Mainlist = GUICtrlCreateList("", -1,-1, 615, 1) GUISetState() TCPStartup() $MainSocket = TCPListen(@IPAddress1, 1234) While 1 $TCPAccept = TCPAccept($MainSocket) $TCPRecv = TCPRecv($TCPAccept, 9999999) If $TCPRecv = "on" Then GUICtrlSetData($Mainlist , $TCPRecv) If $TCPRecv <> "on" Then GUICtrlSetData($Mainlist , "") WEnd this is working fine if i runned the sender code multiple times and fast enough i'll see it in my list but i can't get it to always send the "on" message i tried this TCPStartup() $TCPcon = TCPConnect (@IPAddress1, 1234) While 1 TCPSend($TCPcon, "on") WEnd but it doesn't worked any ideas ? Link to comment Share on other sites More sharing options...
Developers Jos Posted October 5, 2013 Developers Share Posted October 5, 2013 TCPaccept() shouldn't be in your loop. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Celtic88 Posted October 5, 2013 Share Posted October 5, 2013 Try #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Form1", 615, 227) $Mainlist = GUICtrlCreateList("", -1, -1, 615, 227) GUISetState() Global $TCPAccept TCPStartup() $MainSocket = TCPListen(@IPAddress1, 1234) _TCPAccept() While 1 $TCPRecv = TCPRecv($TCPAccept, 9999999) If @error Then GUICtrlSetData($Mainlist, "Off") _TCPAccept() EndIf GUICtrlSetData($Mainlist, $TCPRecv) Sleep(200) WEnd Func _TCPAccept() Do $TCPAccept = TCPAccept($MainSocket) Until Not @error EndFunc ;==>_TCPAccept server TCPStartup() Do $TCPcon = TCPConnect(@IPAddress1, 1234) Until Not @error While 1 TCPSend($TCPcon, "on") Sleep(200) WEnd Alexxander 1 Link to comment Share on other sites More sharing options...
Alexxander Posted October 5, 2013 Author Share Posted October 5, 2013 Try #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Form1", 615, 227) $Mainlist = GUICtrlCreateList("", -1, -1, 615, 227) GUISetState() Global $TCPAccept TCPStartup() $MainSocket = TCPListen(@IPAddress1, 1234) _TCPAccept() While 1 $TCPRecv = TCPRecv($TCPAccept, 9999999) If @error Then GUICtrlSetData($Mainlist, "Off") _TCPAccept() EndIf GUICtrlSetData($Mainlist, $TCPRecv) Sleep(200) WEnd Func _TCPAccept() Do $TCPAccept = TCPAccept($MainSocket) Until Not @error EndFunc ;==>_TCPAccept server TCPStartup() Do $TCPcon = TCPConnect(@IPAddress1, 1234) Until Not @error While 1 TCPSend($TCPcon, "on") Sleep(200) WEnd ya so nice piece of code it is working but it is giving 2 lines when i run the sender 1 time thank you so much i'll try to fix it Link to comment Share on other sites More sharing options...
Celtic88 Posted October 5, 2013 Share Posted October 5, 2013 have fun! #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Form1", 615, 227) $Mainlist = GUICtrlCreateList("", -1, -1, 615, 227) GUISetState() Global $TCPAccept TCPStartup() $MainSocket = TCPListen(@IPAddress1, 1234) _TCPAccept() While 1 $TCPRecv = TCPRecv($TCPAccept, 9) If @error Then GUICtrlSetData($Mainlist, "") _TCPAccept() ContinueLoop EndIf If $TCPRecv <> "" Then GUICtrlSetData($Mainlist, $TCPRecv) Sleep(100) WEnd Func _TCPAccept() GUICtrlSetData($Mainlist, "Off") Do $TCPAccept = TCPAccept($MainSocket) Until $TCPAccept <> -1 GUICtrlSetData($Mainlist, "") EndFunc ;==>_TCPAccept Alexxander 1 Link to comment Share on other sites More sharing options...
Alexxander Posted October 5, 2013 Author Share Posted October 5, 2013 have fun! #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Form1", 615, 227) $Mainlist = GUICtrlCreateList("", -1, -1, 615, 227) GUISetState() Global $TCPAccept TCPStartup() $MainSocket = TCPListen(@IPAddress1, 1234) _TCPAccept() While 1 $TCPRecv = TCPRecv($TCPAccept, 9) If @error Then GUICtrlSetData($Mainlist, "") _TCPAccept() ContinueLoop EndIf If $TCPRecv <> "" Then GUICtrlSetData($Mainlist, $TCPRecv) Sleep(100) WEnd Func _TCPAccept() GUICtrlSetData($Mainlist, "Off") Do $TCPAccept = TCPAccept($MainSocket) Until $TCPAccept <> -1 GUICtrlSetData($Mainlist, "") EndFunc ;==>_TCPAccept Thanks a lot buddy i really appreciate your help your script is perfect but may i ask a little question ? when i remove the _TCPAccept() from line 11 nothing change if i removed it wont affect anything right ? and also the ContinueLoop is useless here ? please correct me if i'm wrong 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