Jump to content

Sending Arrays via TCP?


Slythfox
 Share

Recommended Posts

I'm trying to send data from a client to a server, but I want to send multiple values at one time (thus use an array). But I can't get it to work.

On client-side, I have this:

[...]
While 1
   ; InputBox for data to transmit
    $Data[1] = InputBox("Send Message", "Send a message.", "")
    $Data[2] = InputBox("Send Message", "Send a second message.", "")
    
   ; If they cancel the InputBox or leave it blank we exit our forever loop
    If @error Or $Data[1] = "" Or $Data[2] = "" Then
        ExitLoop
    EndIf
    
; Send data.
    TCPSend($ConnectedSocket, $Data)
    If @error Then
        ExitLoop
    EndIf
WEnd
[...]

On server-side, I have this:

[...]
While 1
; Try to recive up to 2048 bytes.
    $Receive = TCPRecv( $ConnectedSocket, 2048 )
    
; Use received data if given.
    If $Receive <> "" Then
        MsgBox(0, "Message", $Receive[1] & "" & $Receive[2])
    EndIf
WEnd
[...]
Link to comment
Share on other sites

  • Developers

Nope. Because that is now fixed... the problem I'm having here is that the server doesn't react upon the recieved signal. There's no error. It just doesn't do anything.

To me this is a clear case of wanting to Run before knowing how to walk...

Open the Helpfile.

Look at the examples provided.

Understand and try them ...

I am sure that will give you a proper start...

Same counts for the Array question...

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

To me this is a clear case of wanting to Run before knowing how to walk...

Open the Helpfile.

Look at the examples provided.

Understand and try them ...

I am sure that will give you a proper start...

Same counts for the Array question...

That sure was helpful... You lead me into the wrong area. I understand that there is a helpfile area, but sometimes it just doesn't help. I'm not new to arrays (just in AutoIt, which means there's a twist or two in how they work). I know the walk, just on different terrain. I have to get used to the terrain, and sometimes reading a book about how to walk on the new terrain just doesn't help.

Here's the issue. The following script works like it should. My TCP script works like this (even though it doesn't work):

Dim $array[3]
Dim $newarray[3]

$array[1] = "foo"
$array[2] = "bar"
$newarray = $array
MsgBox(0, "", $newarray[1] & "" & $newarray[2])
Alright. But how come it doesn't work when the $array is being transfered via TCP ($newarray)? See what I mean?

So then, perhaps it has to do with this line from the server-side. I'm not quite sure what to do with it...

If $Receive <> "" Then
Edited by Slythfox
Link to comment
Share on other sites

if your trying to send an array from one computer to another try doing something like this(not full code):

Sender

Local $avArray[3] = ["test1", "test2", "test3"]
Local $tcpString
For $i = 0 to 2
        $tcpString &= $avArray[$i] & "|"
Next
TCPSend($socket, $tcpString)
oÝ÷ Ùz+Þ­«­¢+Ø(ÀÌØíÑôQ
AIØ ÀÌØíͽ­Ð°ÈÀÐà¤(ÀÌØíÙÉÉäôMÑÉ¥¹MÁ±¥Ð ÀÌØíÑ°ÅÕ½ÐíðÅÕ½Ðì¤(

Now.. you have that same array on the other side...

Link to comment
Share on other sites

if your trying to send an array from one computer to another try doing something like this(not full code):

Sender

Local $avArray[3] = ["test1", "test2", "test3"]
Local $tcpString
For $i = 0 to 2
        $tcpString &= $avArray[$i] & "|"
Next
TCPSend($socket, $tcpString)
oÝ÷ Ùz+Þ­«­¢+Ø(ÀÌØíÑôQ
AIØ ÀÌØíͽ­Ð°ÈÀÐà¤(ÀÌØíÙÉÉäôMÑÉ¥¹MÁ±¥Ð ÀÌØíÑ°ÅÕ½ÐíðÅÕ½Ðì¤(

Now.. you have that same array on the other side...

Thanks. That works perfectly.
Link to comment
Share on other sites

  • Developers

That sure was helpful... You lead me into the wrong area. I understand that there is a helpfile area, but sometimes it just doesn't help. I'm not new to arrays (just in AutoIt, which means there's a twist or two in how they work). I know the walk, just on different terrain. I have to get used to the terrain, and sometimes reading a book about how to walk on the new terrain just doesn't help.

I do still think I pointed you to the right area for the TCPIP Functions.. the helpfile has examples of working TCPIP scripts which will help as a start.

As far as you being familiar with Arrays in other program languages: The helpfile does explain how Arrays are implemented in AutoIT3 so should be very easy for you to pickup ...

The code you have shown in the couple of post today led me to making this remark.. no offence intended..

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I do still think I pointed you to the right area for the TCPIP Functions.. the helpfile has examples of working TCPIP scripts which will help as a start.

I've been using several different TCP scripts as examples... Including the ones from the helpfile. :P But they don't help solve all the problems I run into.

As far as you being familiar with Arrays in other program languages: The helpfile does explain how Arrays are implemented in AutoIT3 so should be very easy for you to pickup ...

Sometimes it's just hard to know where to start. I hadn't even bothered to look at the array helpfiles at the time because I made several assumptions about arrays :). Guess I won't be doing that again.
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...