vdankbaar

Having some problems with arrays

2 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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