Sign in to follow this  
Followers 0
nake89

IM?

4 posts in this topic

I just want to get the basic idea on how to make an IM.

I have looked at alot of scripts and all I see ist TCP and UDF.

And I dont have a clue on what they are since they arent

displayed in the autoit help-file... :whistle:

THANK YOU!

Share this post


Link to post
Share on other sites



Actually they ARE in the AutoIt helpfile (and it's UDP, not UDF). You just probably need the beta version of AutoIt. Check my signature for links.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If you need more help, check my signature for my fileman and download either AutoIt Archive.zip which has 20+ scripts experimenting with it, or download PIM 1.0 which deals with it..... You will need the beta. http://www.autoitscript.com/autoit3/files/beta/autoit/

It's quite simple:

Dim $ConnectedSocket = -1, $port = 200
;Creates a Socket variable for reading nad port variable
TCPStartup()
;Turns on Transmission Control Protocol services
$OriginalSocket = TCPListen("127.0.0.1", $port)
;Allows incoming connections and creates a Socket Identifier
#include <GuiConstants.au3>
GUICreate("Basic IM", 215, 165, (@DesktopWidth - 215) / 2, (@DesktopHeight - 165) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$history = GUICtrlCreateLabel("", 10, 10, 200, 90, $SS_SUNKEN)
$Output = GUICtrlCreateInput("", 10, 110, 200, 20)
$Connect = GUICtrlCreateButton("Connect To...", 10, 140, 100, 20)
$Send = GUICtrlCreateButton("Send", 110, 140, 100, 20)
GUISetState()
While 1
    $msg = GUIGetMsg()
;If there is no connection, then check for one...
    If $ConnectedSocket = -1 Then
        $ConnectedSocket = TCPAccept($OriginalSocket)
    EndIf
;If you receive any data then tell.....
    $InData = TCPRecv($ConnectedSocket, 999)
    If $InData <> "" And $InData <> "~~bye" Then
   ;InData is valid, write to gui.
        GUICtrlSetData($history, GUICtrlRead($history) & @CRLF & ">" & $InData)
    ElseIf $InData = "~~bye"Then
        TCPCloseSocket($ConnectedSocket)
        $ConnectedSocket = -1
    EndIf
    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    ElseIf $msg = $Send And $ConnectedSocket <> - 1 Then
        $OutData = GUICtrlRead($Output)
        GUICtrlSetData($Output, "")
        GUICtrlSetData($history, GUICtrlRead($history) & @CRLF & "<" & $OutData)
        TCPSend($ConnectedSocket, $OutData)
    ElseIf $msg = $Connect And $ConnectedSocket = -1 Then
        $IpAddress = InputBox("Connect to....", "Input IpAddress to connect to.....", "", " ", "200", "130", "-1", "-1")
        If @error = 0 Then;OK - The string returned is valid
            $ConnectedSocket = TCPConnect($IpAddress, $port)
        EndIf
    EndIf
WEnd
Func OnAutoItExit()
    TCPCloseSocket($ConnectedSocket)
    TCPCloseSocket($OriginalSocket)
    TCPShutdown
EndFunc ;==>OnAutoItExit

Using this you cannot connect to yourself, unless you have two windows open and use the second window. It's the same as PIM 1.0, read here:

http://www.autoitscript.com/forum/index.php?showtopic=15402

Also if behind a router it will not work unless you forward the port data.

UDP(User Datagram Protocol) works the same way only with different calls, and I havn't experimented with Server/Client hybrid in UDP yet.

I hope this helps!

AutoIt Smith

P.S. I just made that Basic in 5 minutes so it's relitivly easy, although I do know TCP functions like the back of my hand now since the past month has been nothing but that. My Remote Server deals with input call strings, check it out here:

http://www.autoitscript.com/forum/index.php?showtopic=15408

Edited by AutoIt Smith

Share this post


Link to post
Share on other sites

I don't think UDP can do im like TCP, it seems the way they developed the UDP functions is that it was for Server to Client only. I got this code so for but the original connecting client wont receive information....

Dim $port = 200, $CSocket = -1
UDPStartUp ()
$OriginalSocket = UDPBind("127.0.0.1", $port)
#include <GuiConstants.au3>
GUICreate("Basic IM", 215, 165, (@DesktopWidth - 215) / 2, (@DesktopHeight - 165) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$history = GUICtrlCreateLabel("", 10, 10, 200, 90, $SS_SUNKEN)
$Output = GUICtrlCreateInput("", 10, 110, 200, 20)
$Connect = GUICtrlCreateButton("Connect To...", 10, 140, 100, 20)
$Send = GUICtrlCreateButton("Send", 110, 140, 100, 20)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    ElseIf $msg = $Send Then
        $OutData = GUICtrlRead($Output)
        GUICtrlSetData($Output, "")
        GUICtrlSetData($history, GUICtrlRead($history) & @CRLF & "<" & $OutData)
        UDPSend($OriginalSocket, $OutData)
    ElseIf $msg = $Connect Then
        $IpAddress = InputBox("Connect to....", "Input IpAddress to connect to.....", "", " ", "200", "130", "-1", "-1")
        If @error = 0 Then;OK - The string returned is valid
            $CSocket = UDPOpen($IpAddress, $port)
            UDPSend($CSocket, "~~connect")
            GUICtrlSetData($history, "New Connection!")
        EndIf
    EndIf
    $InData = UDPRecv($OriginalSocket, 999)
    If $InData <> "" And $InData <> "~~connect" And $InData <> "~~bye" Then
        GUICtrlSetData($history, GUICtrlRead($history) & @CRLF & ">" & $InData)
    ElseIf $InData = "~~connect" Then
        GUICtrlSetData($history, "New Connection!")
    ElseIf $InData = "~~bye" Then
        UDPCloseSocket($OriginalSocket)
        If $CSocket <> - 1 Then UDPCloseSocket($CSocket)
        $OriginalSocket = UDPBind("127.0.0.1", $port)
    EndIf
WEnd
Func OnAutoItExit()
    If $CSocket <> - 1 Then UDPCloseSocket($CSocket)
    UDPCloseSocket($OriginalSocket)
    UDPShutdown ()
EndFunc  ;==>OnAutoItExit

I gotta leave my internet station for a few weeks so be back in a few.

AutoIt Smith

Share this post


Link to post
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
Sign in to follow this  
Followers 0