Insolence Posted March 3, 2005 Share Posted March 3, 2005 (edited) When I host the client and server on the same computer it works. I changed the IP's I even got to test a seperate TCP chat program today, and it worked. Server: expandcollapse popup;SERVER!! Start Me First !!!!!!!!!!!!!!! #include <GUIConstants.au3> $g_IP = "10.46.1.82" ; Start The TCP Services ;============================================== DLLCall("au3xtra.dll","int","TCPStartUp") ; Create a Listening "SOCKET" ;============================================== $MainSocket = DLLCall("au3xtra.dll", "int", "TCPListen", "str", $g_IP, "int", 8080, "int", 100 ) If @ERROR Or $MainSocket[0] = -1 Then Exit $MainSocket = $MainSocket[0] $RogueSocket = -1 ; Create a GUI for chatting ;============================================== $GOOEY = GUICreate("my server",300,200) $edit = GUICtrlCreateEdit("",10,40,280,150,$WS_DISABLED) $input = GUICtrlCreateInput("",10,10,200,20) $butt = GUICtrlCreateButton("Send",210,10,80,20,$BS_DEFPUSHBUTTON) GUISetState() ; Initialize a variable to represent a connection ;============================================== Dim $ConnectedSocket = -1 ; GUI Message Loop ;============================================== While 1 $msg = GUIGetMsg() ; GUI Closed ;-------------------- If $msg = $GUI_EVENT_CLOSE Then ExitLoop ; User Pressed SEND ;-------------------- If $msg = $butt Then If $ConnectedSocket > -1 Then $ret = DLLCall( "au3xtra.dll", "int", "TCPSend", "int", $ConnectedSocket, "str", GUICtrlRead($input)) If @ERROR Or $ret[0] < 0 Then ; ERROR OCCURRED, CLOSE SOCKET AND RESET ConnectedSocket to -1 ;---------------------------------------------------------------- DLLCall( "au3xtra.dll", "int", "TCPCloseSocket", "int", $ConnectedSocket ) WinSetTitle($GOOEY,"","my server - Client Disconnected") $ConnectedSocket = -1 ElseIf $ret[0] > 0 Then ; UPDATE EDIT CONTROL WITH DATA WE SENT ;---------------------------------------------------------------- GUICtrlSetData($edit, GUICtrlRead($edit) & GUICtrlRead($input) & @CRLF ) EndIf EndIf GUICtrlSetData($input,"") EndIf If $RogueSocket > 0 Then $ret = DLLCall("au3xtra.dll","int","TCPRecv", "int", $RogueSocket, "str", "", "int", 512 ) If $ret[0] > 0 Then DLLCall( "au3xtra.dll", "int", "TCPCloseSocket", "int", $RogueSocket ) $RogueSocket = -1 EndIf EndIf ; If no connection look for one ;-------------------- If $ConnectedSocket = -1 Then $ConnectedSocket = DLLCall("au3xtra.dll","int","TCPAccept", "int", $MainSocket) If @ERROR Or $ConnectedSocket[0] < 0 Then $ConnectedSocket = -1 Else WinSetTitle($GOOEY,"","my server - Client Connected") $ConnectedSocket = $ConnectedSocket[0] EndIf ; If connected try to read some data ;-------------------- Else ; EXECUTE AN UNCONDITIONAL ACCEPT IN CASE ANOTHER CLIENT TRIES TO CONNECT ;---------------------------------------------------------------- $RogueSocket = DLLCall("au3xtra.dll","int","TCPAccept", "int", $MainSocket) If Not @ERROR And $RogueSocket[0] > 0 Then $RogueSocket = $RogueSocket[0] DLLCall( "au3xtra.dll", "int", "TCPSend", "int", $RogueSocket, "str", "~~rejected" ) EndIf $ret = DLLCall("au3xtra.dll","int","TCPRecv", "int", $ConnectedSocket, "str", "", "int", 512 ) If $ret[0] > 0 And $ret[2] <> "~~bye" Then ; UPDATE EDIT CONTROL WITH DATA WE RECEIVED ;---------------------------------------------------------------- GUICtrlSetData($edit, GUICtrlRead($edit) & ">" & $ret[2] & @CRLF) ElseIf $ret[0] < 0 Or $ret[2] = "~~bye" Then ; ERROR OCCURRED, CLOSE SOCKET AND RESET ConnectedSocket to -1 ;---------------------------------------------------------------- WinSetTitle($GOOEY,"","my server - Client Disconnected") DLLCall( "au3xtra.dll", "int", "TCPCloseSocket", "int", $ConnectedSocket ) $ConnectedSocket = -1 EndIf EndIf WEnd GUIDelete($GOOEY) Func OnAutoItExit() ;ON SCRIPT EXIT close opened sockets and shutdown TCP service ;---------------------------------------------------------------------- If $ConnectedSocket > -1 Then DLLCall( "au3xtra.dll", "int", "TCPSend", "int", $ConnectedSocket, "str", "~~bye" ) Sleep(2000) DLLCall( "au3xtra.dll", "int", "TCPRecv", "int", $ConnectedSocket, "str", "", "int", 512 ) DLLCall( "au3xtra.dll", "int", "TCPCloseSocket", "int", $ConnectedSocket ) EndIf DLLCall( "au3xtra.dll", "int", "TCPCloseSocket", "int", $MainSocket ) DLLCall( "au3xtra.dll", "int", "TCPShutDown") EndFunc Client: expandcollapse popup;CLIENT!!!!!!!! Start SERVER First... dummy!! #include <GUIConstants.au3> $g_IP = "10.46.1.82" ; Start The TCP Services ;============================================== DLLCall("au3xtra.dll","int","TCPStartUp") ; Connect to a Listening "SOCKET" ;============================================== $socket = DLLCall("au3xtra.dll","int","TCPConnect", "str", $g_IP, "int", 8080 ) If @ERROR Or $socket[0] < 0 Then Exit $socket = $socket[0] ; Create a GUI for chatting ;============================================== $GOOEY = GUICreate("my client - Server Connected",300,200) $edit = GUICtrlCreateEdit("",10,40,280,150,$WS_DISABLED) $input = GUICtrlCreateInput("",10,10,200,20) $butt = GUICtrlCreateButton("Send",210,10,80,20,$BS_DEFPUSHBUTTON) GUISetState() ; GUI Message Loop ;============================================== While 1 $msg = GUIGetMsg() ; GUI Closed ;-------------------- If $msg = $GUI_EVENT_CLOSE Then ExitLoop ; User Pressed SEND ;-------------------- If $msg = $butt Then $ret = DLLCall( "au3xtra.dll", "int", "TCPSend", "int", $socket, "str", GUICtrlRead($input)) If @ERROR Or $ret[0] < 0 Then ExitLoop ; Server Disconnected... we Outty... ;--------------------------------------- If $ret[0] > 0 Then GUICtrlSetData($edit, GUICtrlRead($edit) & GUICtrlRead($input) & @CRLF) GUICtrlSetData($input,"") EndIf $ret = DLLCall("au3xtra.dll","int","TCPRecv", "int", $socket, "str", "", "int", 512 ) If $ret[2] = "~~rejected" Then GUICtrlSetData($edit, GUICtrlRead($edit) & "~~Connection Rejected" & @CRLF) WinSetTitle($GOOEY,"","Connection Rejected") Sleep(2000) DLLCall( "au3xtra.dll", "int", "TCPSend", "int", $socket, "str", "~~whatever") ExitLoop ElseIf $ret[2] = "~~bye" Then GUICtrlSetData($edit, GUICtrlRead($edit) & "~~Connection Lost" & @CRLF) WinSetTitle($GOOEY,"","Connection Lost") Sleep(2000) ExitLoop EndIf If $ret[0] < 0 Then ExitLoop ; Server Disconnected... we Outty... ;--------------------------------------- If $ret[0] > 0 Then GUICtrlSetData($edit, GUICtrlRead($edit) & ">" & $ret[2] & @CRLF) WEnd Func OnAutoItExit() DLLCall( "au3xtra.dll", "int", "TCPSend", "int", $socket, "str", "~~bye" ) DLLCall( "au3xtra.dll", "int", "TCPCloseSocket", "int", $socket ) DLLCall( "au3xtra.dll", "int", "TCPShutDown") EndFunc I know the IP is right and stuff... because I used it with a different program and it went smoothly. Edited March 3, 2005 by Insolence "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Nova Posted March 3, 2005 Share Posted March 3, 2005 Have you considered that the computer in school you are trying to run the server on may have a firewall ? Link to comment Share on other sites More sharing options...
Insolence Posted March 3, 2005 Author Share Posted March 3, 2005 Did you read that I used a seperate TCP program and it worked? "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Blue_Drache Posted March 3, 2005 Share Posted March 3, 2005 what port does the other prog use?try a common port like 23 or 3389 or some other one that is likely not to be firewalled.Lar.<{POST_SNAPBACK}>He used port 8080...that's usually the standard proxy port and not likely to be firewalled. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Insolence Posted March 4, 2005 Author Share Posted March 4, 2005 The other TCP program I used to chat also used port 8080, that's why I changed it from the default one and 21 (which I successfully used to connect to my FTP) "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Insolence Posted March 4, 2005 Author Share Posted March 4, 2005 bump* "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Insolence Posted March 6, 2005 Author Share Posted March 6, 2005 bump... "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
therks Posted March 6, 2005 Share Posted March 6, 2005 (edited) One thing I just wanted to ask. Wouldn't it be wiser to DllOpen the dll, and then call from the handle? That way it doesn't have to load and unload the dll all the time, right? Example:$dll = DllOpen("user32.dll") $result = DllCall($dll, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0) DllClose($dll) *Edit: Also, where can I get my hands on a compiled au3xtra.dll? I did a quick search but all I could find was Larry's source code. *Edit2: Nevermind, I found one here on my computer actually. Is it the most recent though? Last modified time is January 26, 2005. Edited March 6, 2005 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Insolence Posted March 6, 2005 Author Share Posted March 6, 2005 Yes that would be faster, but I'm not sure if it really matters in this case. IF you search for 'TCP' in the Scripts/Scraps forum you can get a lot of examples for this:au3xtra.dll "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
therks Posted March 6, 2005 Share Posted March 6, 2005 That's weird... using your attached dll there, AutoIt locks up, can't even close it with out End Task. If I use mine it's fine. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Insolence Posted March 6, 2005 Author Share Posted March 6, 2005 I just grabbed the first one I found, it might be a buggy version "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
Insolence Posted March 7, 2005 Author Share Posted March 7, 2005 bump again...* "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. 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