Python Forum
Send raw string via socket with out any changes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send raw string via socket with out any changes
#8
john36 Wrote:becose i didn't know yet how will be look like this variable, I will be have many different data \xab\xcd\xef\xgh...
I understand that you can't hard code the variable in your program because its content will vary in time. However, this contents must be coming from somewhere, either read in a file or created by some other python function etc. Can you send more complete code that shows how you want to generate the data before sending it throw the socket?

The important thing that you need to understand is that there are two types of strings in python: unicode strings, which type is str, and which is mainly used to transmit human readable messages, and byte strings, which type is bytes used for binary data and obviously this is what the labeller is expecting. Besides these two types, there is a syntactic difference to allow you to hard code both types of strings in code and this is the 'b', so when you write
foo = 'foo'
bar = b'bar'
the value of foo has type str (unicode string, for humans) and the value of bar has type bytes (binary data, for machines).
Reply


Messages In This Thread
RE: Send raw string via socket with out any changes - by Gribouillis - Jul-24-2019, 09:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Send data BMP180 between client and server trought module socket smalhao 0 2,883 Jul-30-2018, 12:56 PM
Last Post: smalhao
  Simple send and recive string Server/Client Epilepsy 1 2,820 May-01-2018, 08:17 PM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

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