Jump to content

TCP Chat help =P


Recommended Posts

: EDIT I solved my last problem that was previously on this thread so I changed it:

I have a little console program and I want it to also send & recieve messages, although, posting it here would vause you to have to read 500+ lines, and so, I won't post it.

I'm not sure why tis wont work, but it may be becasue of one of these:

a) LAN

:) I didn't code it right

c) I should be using WAN rather then my LAN address

Any way, I looked at the example forum and saw this thing on remote autoit, and I dissected it and stole some parts(the following is my script):

($input1 is my input box)

($interface is a edit box)

($button1 is my send button)

TCPStartup()
$Ip = @IPAddress1
$Port = 5900
$Incoming = TCPListen($Ip, $Port)

;gui stuff here

While 1
If $ALLOWCHAT = True Then
    $Con = TCPAccept($Incoming)
    $msg = TCPRecv($con, 5000)
    If $msg <> "" Then
        GUICtrlSetData($Interface, GUICtrlRead($Interface) & @CRLF & $msg)
    EndIf

;alot of script here

        Case $Button1
            If $CLEAR = True Then GUICtrlSetData($Interface, "")
            $CMD = GUICtrlRead($Input1)
            $last = GUICtrlRead($Input1)
            $CMDLN = StringTrimRight($CMD, StringLen($CMD) - 5)
            GUICtrlSetData($Input1, "")
            GUICtrlSetData($Interface, GUICtrlRead($Interface) & @CRLF & "[" & $USER & "]: " & $CMD)
            Select
                Case $CMDLN = "/snd "
                    If $ALLOWCHAT = True Then
                    TCPSend($con2, "[" & $USER & "]: " & StringTrimLeft($CMD, 5))
                Else
                    GUICtrlSetData($Interface, GUICtrlRead($Interface) & @CRLF & "-Chat is disabled")
                    EndIf
            EndSelect

;about 300 more lines of script here

        Case $MenuItem26
            If $ALLOWCHAT = False Then
                GUICtrlSetState($MenuItem26, $GUI_CHECKED)
                $ALLOWCHAT = True
                $ip2 = InputBox("IP", "Enter IP to connect to", @IPAddress1)
                $port2 = InputBox("Port", "What port are they using?", "5900")
                $con2 = TCPConnect($ip, $port)
            Else
                GUICtrlSetState($MenuItem26, $GUI_UNCHECKED)
                $ALLOWCHAT = False
            EndIf

OK, so $ALLOWCHAT is false at start, then you clicksomething ($menuitem26) and it'll switch $ALLOWCHAT to TRUE, then ask you for what to connect to, and ALSO by switching on $ALLOWCHAT, the script SHOULD start writing anything incomming to the $interface, and also, you SHOULD be able to type (/snd <text>) and click $button1 and it SHOULD have sent it to the address you typed earlier when you allowed chat...

problem is, it DOESN'T do what it SHOULD..

and I'm lost here XD

Edited by MethodZero

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

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