Overkill Posted November 23, 2008 Share Posted November 23, 2008 I am looking for a way to set up a specific computer so that it can force other PCs on the LAN to shut down at certain times, or on a button press. Most of that code I can write myself, but the TCP stuff isn't making much sense to me and I could use some help figuring it out. I've been looking at the TCP functions and it seems possible with a server script (server is supposed to be on 24/7) and a client script to force a client to accept a message from the server, then run a certain UDF if that message fits an IF/ELSEIF condiiton. Can somebody link a tutorial or give me some sample code to play with? Thanks, Overkill Link to comment Share on other sites More sharing options...
Dampe Posted November 23, 2008 Share Posted November 23, 2008 (edited) Top of my head, This is only a single user server, mutli-user server easily do-able with arrays. Server: expandcollapse popupLocal $TCPMainSocket HotKeySet("{HOME}", "SendFunc") TCPStartup() $TCPListenSocket = TCPListen(@IPAddress1, 1081) While 1 $TCPMainSocket = TCPAccept($TCPListenSocket) If $TCPMainSocket >= 0 Then ExitLoop EndIf WEnd While 1 $TCPRecv = TCPRecv($TCPMainSocket, 2048) If $TCPRecv <> "" Then ConsoleWrite($TCPRecv & @CRLF) EndIf WEnd Func SendFunc() If $TCPMainSocket >= 0 Then $tSend = InputBox("Send function", "Enter a function to send", "shutdown") If $tSend <> "" Then TCPSend($TCPMainSocket, $tSend) EndIf EndIf EndFunc ;==>SendFunc Client: TCPStartup() Local $ServerIP = @IPAddress1 $TCPMainSocket = TCPConnect($ServerIP, 1081) If $TCPMainSocket = -1 Then MsgBox(48, "TCP error", "Server is not running") TcpShutdown() Exit 0 EndIf While 1 $TCPRecv = TCPRecv($TCPMainSocket, 2048) If $TCPRecv <> "" Then _CheckFunc($TCPRecv) EndIf WEnd Func _CheckFunc($tFunc) If $tFunc = "shutdown" Then ;//Server is requesting a shutdown TcpSend ($TCPMainSocket, @ComputerName & " is shutting down.") TcpShutdown() Shutdown(1) EndIf EndFunc ;==>_CheckFunc Edited November 23, 2008 by Dampe Link to comment Share on other sites More sharing options...
Overkill Posted November 23, 2008 Author Share Posted November 23, 2008 That helped a lot...I haven't gotten around to reverse engineering the code and understanding what it does yet but it's on the to-do list =) Next question...variable variables... How might I get this code to actually work? $ComputerA = "192.168.10.1" $ComputerB = "192.168.10.8" $ComputerC = "192.168.10.19" $okbutton = GUICtrlCreateButton("OK",170,10,60,23) $combobox = GUICtrlCreateCombo("", 10,10,150) GUICtrlSetData($combobox,"ComputerA|ComputerB|ComputerC") While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit If $msg = $okbutton Then StatusCheck() Wend Func StatusCheck() $selectedcomp = GUICtrlRead($combobox) $pingtime = Ping($$selectedcomp) ; Other code will go here EndFunc 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