Jump to content

Having some problems with arrays


Recommended Posts

Hi everyone,

Its my first time on the fourm so take it easy on me if i make some mistakes.

I recently started programming with Auto it but I'm having some trouble with arrays.

I'm making a tcpchat and I have made a client and server script.

Everything works exept for when the client sends some text to the server.

The idea is that the server sends the text to all the clients, But I can't figure out how to use tcpsend with a array (Keep in mind that I want to send the text to the whole array aka. all the clients).

Here is the code i have at the moment. If the solution is simple then i'm sorry but i wasen't able to find anything on the subject.

;this is my code (the server)

#include <Array.au3>
setup()
sender()
afsluiten()

func setup()
Global $clientcount=0
global $ip=InputBox("Chatservice", "voer je eigen ip in")
global $port=InputBox("Chatservice", "voer een port in tussen 1000-6500 om op te hosten")
global $maxusers=InputBox("Chatservice", "hoeveel mensen mogen maximaal mee chaten")

TCPStartup()
Dim $Socket_Data[$maxusers]
$Socket_Data[0] = 0
$Listen = TCPListen($ip, $port, $maxusers)
While 1
    For $x = $Socket_Data[0] To $maxusers Step -1
        global $Recv = TCPRecv($Socket_Data[$x], 4096)
    Next
    _Accept()
WEnd
Func _Accept()
    Local $Accept = TCPAccept($Listen)
    If $Accept <> -1 Then
        _ArrayAdd($Socket_Data, $Accept)
        $Socket_Data[0] += 1
    EndIf
EndFunc
endfunc

func sender()
While 1

if $Recv then

;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

;here is the problem

;i want $clients to include  the whole array but it doesn't
TCPSend($clients, $Recv)

;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

endif
WEnd
EndFunc

Func afsluiten()
   TCPSend($isock2, $recv)
   TCPCloseSocket($isock)
   TCPCloseSocket($Socket1)
   TCPCloseSocket($isock2)
   TCPCloseSocket($Socket2)
   TCPCloseSocket($client1)
   TCPCloseSocket($client2)
   TCPShutdown()
EndFunc

Edited by vdankbaar
Link to comment
Share on other sites

For $i = 1 to $clients[0] ; When the array holds the number of entries in the first element
For $i = 0 to UBound($clients) - 1 ; When the array doesn't hold the number of entries in the first element

One of this two should do the trick ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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