Alexxander Posted October 12, 2013 Share Posted October 12, 2013 (edited) HI all i'm having a very bad time in Autoit TCP i'm going to loose my mind i cant understand it i'm working on a local network program i'm the server and 4 local pc are clients i must see if the 4 PCs are turned on or not , the online ones must be listed in a GUI listview i tried this server #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Form1", 615, 227) $Mainlist = GUICtrlCreateList("PC Name|Operating system", -1, -1, 615, 227) GUISetState() Global $TCPAccept TCPStartup() $MainSocket = TCPListen(@IPAddress1, 1234) While 1 $TCPRecv = TCPRecv($TCPAccept, 999999999) If @error Then _TCPAccept() If $TCPRecv <> "" Then GUICtrlSetData($Mainlist, $TCPRecv) Sleep(100) WEnd Func _TCPAccept() GUICtrlSetData($Mainlist, "") Do $TCPAccept = TCPAccept($MainSocket) Until $TCPAccept <> -1 GUICtrlSetData($Mainlist, "") EndFunc ;==>_TCPAccept client TCPStartup() Do $TCPcon = TCPConnect(@IPAddress1, 1234) Until Not @error While 1 TCPSend($TCPcon, "on") Sleep(200) WEnd it is working for 1 client but i cant get it to work if I had more than 1 client this thread is very useful>http://www.autoitscript.com/forum/topic/...onnection/ i still cant use it for my program i'm so confused may u direct m to the right way ? i must use arrays right ? how can i show an array in a GUI list view please may you give me an example about MULTI CLIENT and a list that view online ones Edited October 12, 2013 by Alexxander Link to comment Share on other sites More sharing options...
mrflibblehat Posted October 12, 2013 Share Posted October 12, 2013 (edited) As you are using TCP, I believe that AutoIT TCPAccept will only accept one connection, Until that connection is closed/timed out it wont accept any more. (please correct me if I'm wrong) You could look at using UDP as its connectionless. Edited October 12, 2013 by mrflibblehat [font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font] Link to comment Share on other sites More sharing options...
bogQ Posted October 17, 2013 Share Posted October 17, 2013 (edited) ------- im correcting you with this link it will show you picture from 3 comps on network connected with driveresial as their identificator over TCP with no problems in that topic that picture is from my old striped code ( ) that i implemanted in example that op is using, that old example shud be usable still (i think) and it already have one small "an array in a GUI list view" in itself ------- From what i see on first look from OPs code is that he have If @error Then _TCPAccept(), that part isnt good, coz if you dont get anything from client youl gona bee traped (@error is set if it dont recive anything) inside accept do untill loop till someone new connect so you do not need "do untill" on accept just puit accept in normal main lop as normall call to func, and you do not need if error to call accept, you only need to call accept and nothing else, "if error" shud not b connected in any way to your accept func and accep dont need inside lop that will pause rest of script. as for array i did explain on example post how its working you set empty array where first element is there to count connections other elements are automaticly added when new user connect if you add gui you only need instead "to display data on msgbox" to display it in gui wiith some gui command, shud that b input list listview or something third its your choice how to redirect data from script to displayu it to where you need it edit: small working example but youl need to work on it ofcors and b shure to read comment on timeint so that you can sort out if client isnt responding anymore expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> GUICreate("Form1", 615, 227) $hListView = GUICtrlCreateListView("ID|PC Name|Operating system|timeint", -1, -1, 615, 227) ;timeint can b used if comp dcced to decide to delite socket and clear listview and update its and array index position, so this part i leave to you to sorte out :) _GUICtrlListView_AddItem($hListView, "1", 0) _GUICtrlListView_AddItem($hListView, "2", 0) _GUICtrlListView_AddItem($hListView, "3", 0) _GUICtrlListView_AddItem($hListView, "4", 0) GUISetState() TCPStartup() Dim $Socket_Data[1] $Socket_Data[0] = 0 $Listen = TCPListen(@IPAddress1, 1018, 500) If @error Then ConsoleWrite('!--> TCPListen error number ( ' & @error & ' ), look in the help file (on MSDN link) on func TCPListen to get more info about this error.' & @CRLF) Exit EndIf While 1 For $x = $Socket_Data[0] To 1 Step -1 $Recv = TCPRecv($Socket_Data[$x], 1000000) If $Recv Then $data = StringSplit($Recv,'$') _GUICtrlListView_AddSubItem($hListView,$x-1,$data[1],1) _GUICtrlListView_AddSubItem($hListView,$x-1,$data[2],2) _GUICtrlListView_AddSubItem($hListView,$x-1,TimerInit(),3) EndIf Next _Accept() WEnd Func _Accept() Local $Accept = TCPAccept($Listen) If $Accept <> -1 Then _ArrayAdd($Socket_Data, $Accept) $Socket_Data[0] += 1 EndIf EndFunc ;==>_Accept TCPStartup() $Socket = TCPConnect(@IPAddress1, 1018) If @error Then ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ), look in the help file (on MSDN link) on func TCPConnect to get more info about this error.' & @CRLF) Exit EndIf While 1 TCPSend($Socket, @ComputerName &'$'& @OSVersion) Sleep(1000) WEnd dont forget to use real server IP networ adress on clients script instead @IPAddress1 macro Edited October 17, 2013 by bogQ Alexxander 1 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...
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