Jump to content

Can't get Larry's TCP dll to work


Recommended Posts

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:

;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:

;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 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

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

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

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

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

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

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 by Saunders
Link to comment
Share on other sites

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

I just grabbed the first one I found, it might be a buggy version :lmao:

"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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...