Drakthor Posted June 19, 2009 Share Posted June 19, 2009 I'm making a remote command prompt kind of thing and I'm working on my server and its giving me problems at TCPListen phase and I've checked the helpfile numerous times and can't seem to fix it. Also the "error" MsgBox returns the value 10039. Can anybody help me fix this? Dim $sock[3] Global $recv GLobal $ip = @IPAddress1 $sock[1] = TCPListen($ip, 6667) If $sock[1] = -1 Then MsgBox(0,"Error",@error) EndIf Link to comment Share on other sites More sharing options...
Authenticity Posted June 19, 2009 Share Posted June 19, 2009 No TCPStrartUp()? Link to comment Share on other sites More sharing options...
Drakthor Posted June 19, 2009 Author Share Posted June 19, 2009 (edited) No TCPStrartUp()?Oh God I feel retarded :facepalm: Crawling back to my cave, thank you. EDIT: It still won't stay open #include <Process.au3> Dim $sock[2] Global $recv Global $ip = @IPAddress1 TCPStartup() $sock[0] = TCPListen($ip, 6667) If $sock[0] = -1 Then MsgBox(0, "Error", @error) EndIf While 1 $sock[1] = TCPAccept($sock[0]) $recv = TCPRecv($sock[1], 6144) If @error Then ExitLoop If $recv <> "" Then _RunDOS($recv & " >> C:\temp.txt") $data = FileRead("C:\temp.txt") TCPSend($sock[1], $data) FileDelete("C:\temp.txt") EndIf WEnd TCPShutdown() Like its trayicon flashes for a second and then it disappears and no MsgBox or anything this time. Edited June 19, 2009 by thejay2012 Link to comment Share on other sites More sharing options...
crashdemons Posted June 19, 2009 Share Posted June 19, 2009 (edited) It still won't stay open ... While 1 $sock[1] = TCPAccept($sock[0]) $recv = TCPRecv($sock[1], 6144) If @error Then ExitLoop If $recv <> "" Then _RunDOS($recv & " >> C:\temp.txt") $data = FileRead("C:\temp.txt") TCPSend($sock[1], $data) FileDelete("C:\temp.txt") EndIf WEnd .. You didn't bother to check if the socket returned by TCPAccept is valid. Regardless, you ExitLooped on a Recv Error - not a listen error, This means that if the other party disconnects or you can't receive data, the loop ends and your program closes. Thus, if $sock[1] is invalid, TCPRecv will encounter an error and ExitLoop will break your loop, closing your program. (probably what happened here) You can try ContinueLoop instead to keep looking for the next valid socket, but you'll have to ExitLoop, Exit, or change the While condition to end when you *NEED* the program to end. And for gods sakes, put a Sleep(...) in that loop! Something like this should work (I didn't test it, but you should get my meaning) Alternatively to using ContinueLoop to substitute your exitloop, you could actually do this: ... While 1 $sock[1] = TCPAccept($sock[0]) If $sock[1]>=0 And @error=0 Then; not that the socket can be 0, but -1 is INVALID $recv = TCPRecv($sock[1], 6144) If @error=0 Then If StringLen($recv)>0 Then _RunDOS($recv & " >> C:\temp.txt");find a better way to do an Append $data = FileRead("C:\temp.txt") TCPSend($sock[1], $data) FileDelete("C:\temp.txt") EndIf EndIf TCPCloseSocket($sock[1]) EndIf Sleep(300) WEnd TCPCloseSocket($sock[0]) ... Note: the above code has no conditions to automatically end - either decide where you want to exit, or manually exit via the tray icon. Edited June 19, 2009 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) 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