Python Forum
converting array of things to byte stream to send
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
converting array of things to byte stream to send
#1
Hi all. This may be a stupid question, but I find what I am trying to do quite confusing. Im receiving a GPS sentence from another server, and I would like to convert this sentence to something else, and send it over the wire, basically as bytes, to another server. I've basically got a client and server in two separate pycharm projects on my desktop, and am sending a message over from the client to the server as follows:

# This is a very standard GPS sentence
message = '$GPRMC,145012,A,3417.2967,N,07805.1806,W,000.0,291.9,240517,000.0,W*7D'
Now, in my server program/project, I am receiving this sentence and splitting it by comma
    split_request = request.split(',')
Then what I would like to do is build basically a new string or array of things (or anything really that will get me to my final result) that is basically a few different converted values and send it off to another server as a converted GPS sentence, which is basically a stream of bytes.

So I do my conversion and basically I have the results in an array.
for x in range(12):
            result = eval(convGPRMC[x].format('split_request[x]'))
            split_request[x] = result
            isNavGPRMC[x] = split_request[x]
So now, of course, I have a function that converts all of those values and drops them into the isNavGPRMC[] array and now I have all of my values.

Now I want to take that isNavGPRMC[] array which is 12 values and send them over the wire to another server, and the server should receive something like 0A 5b 6C 4D etc. etc. (those are just random numbers).

How can I :
1. Print the isNavGPRMC[] array as ascii characters
2. Send those ascii characters over 'the wire' as a binary stream of those ascii characters (I guess thats how you can put it?)

Hope you can help Big Grin :D Thanks.
Reply
#2
you shouldn't need to convert the string, just send it to the
other server. see: https://stackoverflow.com/questions/3465...a-over-tcp
Reply
#3
Quote:you shouldn't need to convert the string, just send it to the
other server. see: https://stackoverflow.com/questions/3465...a-over-tcp

First off, thanks for the response.

But how can I take each of the 12 values which are in the array isNavGPRMC[] and print them to the console as the hex output that will be sent over to the other server? Also, some of the values in the array might have to be sent out as ASCII and some not. For example, one of the values might have to go out as 0x02 and some as 0x32 to represent 2 in ascii, and not the number 2 hex. This is why I want to print it out to the console so that I am able to debug and see what exactly is going on.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Microphone stream manipulation Talking2442 1 2,684 Nov-19-2023, 02:08 PM
Last Post: palumanic
  EEG stream data with mne and brainfolw PaulC 0 462 Aug-22-2023, 03:17 AM
Last Post: PaulC
  extract only text strip byte array Pir8Radio 7 2,790 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  Can a variable equal 2 things? Extra 4 1,450 Jan-18-2022, 09:21 PM
Last Post: Extra
  Decoding a serial stream AKGentile1963 7 8,339 Mar-20-2021, 08:07 PM
Last Post: deanhystad
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 11,356 Sep-18-2020, 10:10 PM
Last Post: tienttt
  Best Video Quality And Stream Harshil 2 2,194 Aug-19-2020, 09:03 AM
Last Post: Harshil
  convert array of numbers to byte array adetheheat 3 2,732 Aug-13-2020, 05:09 PM
Last Post: bowlofred
  Unusual things to do with unittest/HTMLTestRunner AndyHolyer 0 2,103 Jul-29-2020, 02:43 PM
Last Post: AndyHolyer
  I don't get the order of how things are executed with main() pythonrookie 5 2,512 Jul-21-2020, 01:35 PM
Last Post: pythonrookie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020