Jump to content

Recommended Posts

Posted (edited)

I'm working on a chat program to communicate between me and some friends. I started by editing the TCPSend and TCPRecieve examples in the include file. As it is right now the client will send the first message but the second one never gets to the server.

Client:

GUICreate('Chat', 400, 400)



TCPStartup()

$PreServers1 = IniReadSection('Config.cfg', 'Client-IPs')

$PreServers2 = IniReadSection('Config.cfg', 'Client-Ports')

$PreServers3 = IniReadSection('Config.cfg', 'Client-Pass')

Global $Servers[UBound($PreServers1)][4]

For $i = 0 To UBound($PreServers1) - 1

    $Servers[$i][0] = $PreServers1[$i][1]

    $Servers[$i][1] = $PreServers2[$i][1]

    $Servers[$i][2] = $PreServers3[$i][1]



Next

$Servers[0][0] = UBound($Servers) - 1



GUICtrlCreateEdit('', 5, 25, 390, 290)

$gSend = GUICtrlCreateEdit('', 5, 320, 340, 70)

$gSendButton = GUICtrlCreateButton('Send', 350, 320, 40, 20)

GUISetState()



While 1

    $Msg = GUIGetMsg()

    Select

        Case $Msg = $gSend

            For $i = 1 To $Servers[0][0]

                $Servers[$i][3] = TCPConnect($Servers[1][0], $Servers[1][1])

                Sleep(1000)

                While 1

                    $szData = GUICtrlRead($gSend)

                    GUICtrlSetData($gSend, '')

                    If @error Or $szData = '' Then ExitLoop

                    TCPSend($Servers[$i][3], StringToBinary($szData, 4))

                    If @error Then ExitLoop

                WEnd

            Next

    EndSelect

WEnd

The server is stright out of the help file minus the port being changed to 50000

Edit: Found out the issue was actually in the Edit control (Wrong)

Edit: Solved the issue, it was trying to make a new TCP Connection within the loop and causing issues

New Working Script:

GUICreate('Chat', 400, 400)

TCPStartup()
$PreServers1 = IniReadSection('Config.cfg', 'Client-IPs')
$PreServers2 = IniReadSection('Config.cfg', 'Client-Ports')
$PreServers3 = IniReadSection('Config.cfg', 'Client-Pass')
Global $Servers[UBound($PreServers1)][4]
For $i = 0 To UBound($PreServers1) - 1
    $Servers[$i][0] = $PreServers1[$i][1]
    $Servers[$i][1] = $PreServers2[$i][1]
    $Servers[$i][2] = $PreServers3[$i][1]

Next
$Servers[0][0] = UBound($Servers) - 1

GUICtrlCreateEdit('', 5, 25, 390, 290)
$gSend = GUICtrlCreateEdit('', 5, 320, 340, 70)
ClipPut(GuiCtrlRead($gSend))
$gSendButton = GUICtrlCreateButton('Send', 350, 320, 40, 20)
GUISetState()

Global $Socket = TCPConnect ($Servers[1][0], $Servers[1][1])

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = -3
            Exit
        Case $Msg = $gSendButton
             $Send = GUICtrlRead($gSend)
             GuiCtrlSetData($gSend, '')
             TCPSend($Socket, $Send)
     EndSelect
WEnd
Edited by AliceDemetri
Posted

Please mark your post as solved. Thanks.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...