i am writing a program and i i need to send an array of ints over the network, i can send it as a string but the fact that its a string makes it hard to work with. is there any way i can send it as an array?
Printable View
i am writing a program and i i need to send an array of ints over the network, i can send it as a string but the fact that its a string makes it hard to work with. is there any way i can send it as an array?
If you are using C++, typecast it as a char and send it with a length of arraysize * sizeof(int)
You'd do better posting this into either the forum specific to the language you are working in.
If the array is of a fixed size, you could send each item sequentially. If the array is not fixed size (the end computer doesn't know how many ints it should receive, send the size of the array first.
Are you using TCP or UDP? This could be done pretty quickly with UDP, but TCP would be a bit more difficult. With UDP, you might send something that says "Prepare to receive array of size x" Then send all the items. If some number other than x arrives, you know a packet has been lost.
Something like that, but you probably aren't working in UDP.