Jump to content
Sign in to follow this  

Simple Messenger

Recommended Posts

I have been trying to make a simple messenger to understand the TCP functions. I made a quick sloppy GUI just so i can have an input box and recieve messages. I can't understand what's wrong with my code, so here it is. please help


#include <GUIConstants.au3>

$window = GUICreate ("Messenger", 500, 500)

$inbox = GUICtrlCreateEdit ("", 5, 5, 100, 100)

$input = GUICtrlCreateInput ("", 5, 200, 100, 20)

$send = GUICtrlCreateButton ("Send", 125, 125, 50, 50)

GUISetState ()

TCPStartup ()

$connect = TCPConnect ("", 65432)

$listen = TCPListen ("", 65432)


$msg = GUIGetMsg()

$accept = TCPAccept ($listen)

$recieve = TCPRecv ($accept, 2048)

GUICtrlSetData ($inbox, $recieve)

Switch $msg

Case $send

$message = GUICtrlRead ($input)

TCPSend ($connect, $message)


Until $msg = $GUI_EVENT_CLOSE

TCPShutdown ()

GUIDelete ($window)


Share this post

Link to post
Share on other sites

Your code has some problems, first you use TCPConnect() before TCPListen() that of course will not work.

You also use TCPAccept in the loop, this is not necessary. You should also check if you got something from TCPRecieve before setting the inbox control.

Here's the clean up version of your code :)

#include <GUIConstantsEx.au3> ; Use this instead, since GUIConstants is obsolete 

$window = GUICreate("Messenger", 500, 500)
$inbox = GUICtrlCreateEdit("", 5, 5, 100, 100)
$input = GUICtrlCreateInput("", 5, 200, 100, 20)
$send = GUICtrlCreateButton("Send", 125, 125, 50, 50)

$listen = TCPListen("", 65432)
$connect = TCPConnect("", 65432)
$accept = TCPAccept($listen)

    $msg = GUIGetMsg()

    $recieve = TCPRecv($accept, 2048)
    If $recieve <> "" Then
        GUICtrlSetData($inbox, $recieve)

    Switch $msg

        Case $send
            $message = GUICtrlRead($input)
            TCPSend($connect, $message)

Until $msg = $GUI_EVENT_CLOSE


;~ GUIDelete($window) ;This is redundant
;~ Exit ; So is this

Good luck! :(

Broken link? PM me and I'll send you the file!

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  

  • Create New...