Sign in to follow this  
Followers 0
kjmarket

TCP Prog. How to pop open a chat window between two pc's

9 posts in this topic

#1 ·  Posted (edited)

Ok, so I'm working on a little prog that uses a tcp connection between two pc's, based on the script by AutoIt Smith, that doesnt require a server/client script/prog running. I want to be able to pop open a chat window between me and the person connected to me, or vice versa. How do you accomplish this? Spyrorocks showed me some code to pop open an unclosable window, but how do you open it for both users and allow them to chat?

Also..I pop open a separate window for the chat window, how can I only close the child chat window instead of the entire prog?

Edited by kjmarket

Pink Floyd - The Wall

Share this post


Link to post
Share on other sites



You could download this one of erifash's and see how he's done it, that would be a good start :D

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


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

OK, thats not the same as what I wanted...but it interests me. With that example, would it be possible to send a tcpsend command to just one person in the chat, rather than to the server?


Pink Floyd - The Wall

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Please check my projects. My Signature contains alot of information, also my AutoIt ITS project as solved this solution.

This also contains many useful TCP things, This is the old File-Based ITS

http://www.autoit-its.com/autoit-its/downl.../File-Based.zip

Please search the Beta Server 0.8.1 for the ~pm function.

Edited by AutoIt Smith

Share this post


Link to post
Share on other sites

I've looked at that many, many times...and the answer isnt in there.


Pink Floyd - The Wall

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This is a limited string from the Current server:

Case $String[1] = "~pm"
                    Select
                        Case $String[0] <> 3
                            TCPSend($ConnectedSocket[$SocketNumber], "Invalid Syntax")
                            Return 1
                    EndSelect
                    $Track = 0
                    For $Track = 0 To (UBound($Userlist) - 1) Step 1
                        If $Userlist[$Track] = $String[2] Then $StoredVar = $Track
                    Next
                    TCPSend($ConnectedSocket[$SocketNumber], "Personal Message To " & $Userlist[$StoredVar] & " : " & $String[3])
                    TCPSend($ConnectedSocket[$StoredVar], "Personal Message From " & $Userlist[$SocketNumber] & " : " & $String[3])

You may modify it to work with you server. This works and is tested.

Split the string to allow the message ~pm-username(or socket)-message

$Var = StringSplit($String, "-")
$Var[1] = ~pm
$Var[2] = username/Socket
$Var[3] = Message

This is from 0.8.1 file based.

; Server Stream Functions:
; ~bye
; ~login-USER-PASS-UID
; ~pm-USER-STRING
; ~register-USER-PASS

;.....ex cetera

Case $Text[1] = "~pm"
                SendMessage("Pm From " & GetUser($SocketNumber) & ">" & $Text[3], GetUserCurrentSocket($Text[2]))
                SendMessage("Pm To " & GetUser(GetUserCurrentSocket($Text[2])) & ">" & $Text[3], $SocketNumber)
                FileWriteLine($LogFile, "Pm From " & GetUser($SocketNumber) & " To " & GetUser(GetUserCurrentSocket($Text[2])) & " >" & $Text[3])

Yet another Example, incase you cannot figure it out. ~pm-socketnumber-message

CODE
Global Const $Port = 50911

Global $MaxConc = 100

Global $MainSocket = TCPStartServer($Port, $MaxConc)

If @Error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.")

Global Const $MaxLength = 512

Global $ConnectedSocket[$MaxConc]

Global $CurrentSocket = 0

Local $Track = 0

Global Const $MaxConnection = ($MaxConc - 1)

For $Track = 0 To $MaxConnection Step 1

$ConnectedSocket[$Track] = -1

Next

While 1

$ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)

If $ConnectedSocket[$CurrentSocket] <> -1 Then

$CurrentSocket = SocketSearch()

EndIf

$Track = 0

For $Track = 0 To $MaxConnection Step 1

If $ConnectedSocket[$Track] <> - 1 Then

$Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)

$Data2 = StringSplit($Data, "-")

If $Data = "~bye" Then

TCPCloseSocket($ConnectedSocket[$Track])

$ConnectedSocket[$Track] = -1

$CurrentSocket = SocketSearch()

ElseIf $Data2[1] = "~pm" Then

TCPSend($ConnectedSocket[$Data2[2]], "From Socket #" & $Track & " > " & $Data2[3])

TCPSend($ConnectedSocket[$Track], "To Socket #" & $Data2[2] & " > " & $Data2[3])

ElseIf $Data <> "" Then

TCPSendMessageAll($MaxConnection, $Data)

EndIf

EndIf

Next

WEnd

Func TCPSendMessageAll($ConnectionLimit, $Data)

Local $Track = 0

For $Track = 0 To $ConnectionLimit Step 1

If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data)

Next

EndFunc ;==>TCPSendMessageAll

Func TCPStartServer($Port, $MaxConnect = 1)

Local $Socket

$Socket = TCPStartup()

Select

Case $Socket = 0

SetError(@Error)

Return -1

EndSelect

$Socket = TCPListen(@IpAddress1, $Port, $MaxConnect)

Select

Case $Socket = -1

SetError(@Error)

Return 0

EndSelect

SetError(0)

Return $Socket

EndFunc

Func SocketSearch()

Local $Track = 0

For $Track = 0 To $MaxConnection Step 1

If $ConnectedSocket[$Track] = -1 Then

Return $Track

Else

; Socket In Use

EndIf

Next

EndFunc ;==>SocketSearch

Showing This

For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket[$Track] <> - 1 Then
            $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
            $Data2 = StringSplit($Data, "-")
            If $Data = "~bye" Then
                TCPCloseSocket($ConnectedSocket[$Track])
                $ConnectedSocket[$Track] = -1
                $CurrentSocket = SocketSearch()
            ElseIf $Data2[1] = "~pm" Then
                TCPSend($ConnectedSocket[$Data2[2]], "From Socket #" & $Track & " > " & $Data2[3])
                TCPSend($ConnectedSocket[$Track], "To Socket #" & $Data2[2] & " > " & $Data2[3])
            ElseIf $Data <> "" Then
                TCPSendMessageAll($MaxConnection, $Data)
            EndIf
        EndIf
    Next
Edited by AutoIt Smith

Share this post


Link to post
Share on other sites

Incase you doubted the answer was there, there is the answer 3 times over in 2 server versions and another rebuilt generic version.

Share this post


Link to post
Share on other sites

I didn't mean to imply anything, so hopeully you didnt take it as me saying it didnt work or what not. It's just my AutoIT ignorance showing. I'm learning as I go, and think I have my answer. I appreciate the help, man. Thanks. :D


Pink Floyd - The Wall

Share this post


Link to post
Share on other sites

No problem. Love to help.

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