Jump to content

TCP Instant Messenger


Recommended Posts

Everything looks correct but I cant seem to figure out why my Filewrite wont read $ri and add it two the .txt you can try this out yourself it might be tcp but you can connected it to your own compy. Please help. also if you see any other problems please tell me.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

TCPStartup()

$Form1 = GUICreate("KIM", 141, 241, 192, 114)
$c = 0
$Label1 = GUICtrlCreateLabel("IP Address", 8, 0, 55, 17)
$Input1 = GUICtrlCreateInput("", 8, 24, 121, 21)
$Label2 = GUICtrlCreateLabel("Port", 8, 48, 23, 17)
$Input2 = GUICtrlCreateInput("", 8, 64, 121, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Save Conversation?", 8, 88, 121, 17)
$Input3 = GUICtrlCreateInput("", 8, 128, 121, 21)
$Label3 = GUICtrlCreateLabel("Save As", 8, 112, 44, 14)
$Button1 = GUICtrlCreateButton("Connect", 8, 160, 123, 17)
$Label4 = GUICtrlCreateLabel("Your IP Address:", 8, 184, 83, 17)
$Label5 = GUICtrlCreateLabel(@IPAddress1, 8, 208, 125, 17)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                $ri = GUICtrlRead($Input3)
                $File = String($ri) & ".txt"
                $c = 1
            EndIf
        Case $Button1
            $IP = GUICtrlRead($Input1)
            $Port = GUICtrlRead($Input2)
            If $IP <> "" And $Port <> "" Then
                $TCPListen = TCPListen($IP, $Port)
                $TCPConnect = TCPConnect($IP, $Port)
                GUIDelete()
                _KIM()
            Else
                MsgBox(0, "Error", "You must enter an IP and Port")
            EndIf
    EndSwitch
WEnd

Func _KIM()
    Global $TCPPrevious
    $hForm = GUICreate("KIM", 184, 247, 192, 114)
    $hEdit = GUICtrlCreateEdit("Waiting for Connections...", 0, 0, 177, 193)
    $hInput = GUICtrlCreateInput("", 0, 200, 177, 21)
    $hButton = GUICtrlCreateButton("Send", 48, 224, 75, 17)
    GUISetState(@SW_SHOW)

    Do
        $TCPAccept = TCPAccept($TCPListen)
    Until $TCPAccept <> -1

    GUICtrlSetData($hEdit, "Say Hi...")

    While 1
        $nMsg = GUIGetMsg()
        $TCPRecv = TCPRecv($TCPAccept, 1000000)
        If $TCPRecv <> "" And $TCPRecv <> $TCPPrevious Then
            $TCPPrevious = $TCPRecv
            ConsoleWrite("What is recieved >> " & $TCPPrevious & @CRLF)
            If $TCPPrevious > $TCPPrevious +1 Then
                Do
                    $TCPPrevious = $TCPPrevious + 1
                Until $TCPPrevious = $TCPRecv
            EndIf
            If $TCPPrevious < $TCPPrevious -1 Then
                Do
                    $TCPPrevious = $TCPPrevious - 1
                Until $TCPPrevious = $TCPRecv
            EndIf
            $k = 0
            If $k = 0 Then
                $r = GUICtrlRead($hEdit)
                $k = 1
                GUICtrlSetData($hEdit, $r & @CRLF & $TCPRecv)
            Else
                GUICtrlSetData($hEdit, $r & @CRLF & $TCPRecv)
                $hEdit = GUICtrlRead($hEdit)
            EndIf
        EndIf
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                If $c = 1 Then
                    FileWrite($File, GuiCtrlRead($hEdit))
                Else
                    ConsoleWrite("You Didn't save your data")
                EndIf
                Exit
            Case $hButton
                If $hInput <> "" Then
                    TCPSend($TCPConnect, GUICtrlRead($hInput))
                    GUICtrlSetData($hInput, "")
                Else
                    ConsoleWrite("No data sent")
                EndIf
        EndSwitch
    WEnd
EndFunc
Link to comment
Share on other sites

Everything looks correct but I cant seem to figure out why my Filewrite wont read $ri and add it two the .txt you can try this out yourself it might be tcp but you can connected it to your own compy. Please help. also if you see any other problems please tell me.

I think you just needed a FileOpen()

#include <GUIConstantsEx.au3>

Global Const $Form1 = GUICreate("KIM", 141, 241, 192, 114)
Global Const $Label1 = GUICtrlCreateLabel("IP Address", 8, 0, 55, 17)
Global Const $Input1 = GUICtrlCreateInput("", 8, 24, 121, 21)
Global Const $Label2 = GUICtrlCreateLabel("Port", 8, 48, 23, 17)
Global Const $Input2 = GUICtrlCreateInput("", 8, 64, 121, 21)
Global Const $Checkbox1 = GUICtrlCreateCheckbox("Save Conversation?", 8, 88, 121, 17)
Global Const $Input3 = GUICtrlCreateInput("", 8, 128, 121, 21)
Global Const $Label3 = GUICtrlCreateLabel("Save As", 8, 112, 44, 14)
Global Const $Button1 = GUICtrlCreateButton("Connect", 8, 160, 123, 17)
Global Const $Label4 = GUICtrlCreateLabel("Your IP Address:", 8, 184, 83, 17)
Global Const $Label5 = GUICtrlCreateLabel(@IPAddress1, 8, 208, 125, 17)

GUISetState(@SW_SHOWNORMAL)

TCPStartup()

Global $c = 0

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                $ri = GUICtrlRead($Input3)
                $File = String($ri) & ".txt"
                $c = 1
            EndIf
        Case $Button1
            $IP = GUICtrlRead($Input1)
            $Port = GUICtrlRead($Input2)
            If $IP <> "" And $Port <> "" Then
                $TCPListen = TCPListen($IP, $Port)
                $TCPConnect = TCPConnect($IP, $Port)
                GUIDelete()
                _KIM()
            Else
                MsgBox(0, "Error", "You must enter an IP and Port")
            EndIf
    EndSwitch
WEnd

Func _KIM()
    Local $TCPPrevious
    GUICreate("KIM", 184, 247, 192, 114)
    $hEdit = GUICtrlCreateEdit("Waiting for Connections...", 0, 0, 177, 193)
    $hInput = GUICtrlCreateInput("", 0, 200, 177, 21)
    $hButton = GUICtrlCreateButton("Send", 48, 224, 75, 17)
    GUISetState(@SW_SHOWNORMAL)

    Do
        $TCPAccept = TCPAccept($TCPListen)
    Until $TCPAccept <> -1

    GUICtrlSetData($hEdit, "Say Hi...")

    FileOpen($File, 2)

    While 1
        $TCPRecv = TCPRecv($TCPAccept, 1000000)
        If $TCPRecv <> "" And $TCPRecv <> $TCPPrevious Then
            $TCPPrevious = $TCPRecv
            ConsoleWrite("What is recieved >> " & $TCPPrevious & @CRLF)
            If $TCPPrevious > $TCPPrevious + 1 Then
                Do
                    $TCPPrevious = $TCPPrevious + 1
                Until $TCPPrevious = $TCPRecv
            EndIf
            If $TCPPrevious < $TCPPrevious - 1 Then
                Do
                    $TCPPrevious = $TCPPrevious - 1
                Until $TCPPrevious = $TCPRecv
            EndIf
            $k = 0
            If $k = 0 Then
                $r = GUICtrlRead($hEdit)
                $k = 1
                GUICtrlSetData($hEdit, $r & @CRLF & $TCPRecv)
            Else
                GUICtrlSetData($hEdit, $r & @CRLF & $TCPRecv)
                $hEdit = GUICtrlRead($hEdit)
            EndIf
        EndIf

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                If $c = 1 Then
                    FileWrite($File, GUICtrlRead($hEdit))
                Else
                    ConsoleWrite("You didn't save your data.")
                EndIf
                Exit
            Case $hButton
                If $hInput <> "" Then
                    TCPSend($TCPConnect, GUICtrlRead($hInput))
                    GUICtrlSetData($hInput, "")
                Else
                    ConsoleWrite("No data sent.")
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_KIM
Edited by LaCastiglione
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...