Jump to content

sending array over tcp


Yeik
 Share

Recommended Posts

]If i have two scripts can i do something like

In my experiments i haven't been able to get it to work. would it be better just to send like a beginning line with how big the array is then send each array element individually

or do _arraytostring() function to send it all in one lump, assuming each is a string of course.

$tarray[3]=[1,2,3]
TCPSend($ConnectedSocket, $tarray)
Edited by Yeik
func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

I would use a Arraytostring while sending, and use some non-typical delimeter, like }@#^{ (to avoid using it in text) and after TCPrecv use a StringSplit and give }@#^{ as a delimeter :) Fast, easy and logical ;) Is'nt it? I hope it helped you a little bit. B) Cheers.

Edited by Uriziel01
Link to comment
Share on other sites

I would use a Arraytostring while sending, and use some non-typical delimeter, like }@#^{ (to avoid using it in text) and after TCPrecv use a StringSplit and give }@#^{ as a delimeter :) Fast, easy and logical ;) Is'nt it? I hope it helped you a little bit. B) Cheers.

That is what i was thinking of doing maybe something even more like ¿¡ that im sure i will never use in any of my code. or strings. I just didn't know if there was an easier way.

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

You can also for example use a loop like

but its much dirty and messy, as I now think ArrayToString is simpliest way (but I'll think about it)

dim $example_array[3]=["abc","123","zxc"]
send_array($example_array)
func send_array($arr)
    for $i=0 to UBound($arr)-1
        TCPSend($mainsocket,"arr["&$i&"]>"&$arr[$i])
    Next
    Return 1
endfunc
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...