Question On Bytes and Sockets
Moderator: Coders of Rage
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Question On Bytes and Sockets
So exactly what is a byte? IDK how to ask this, but is it a hex? or binary? or what? When the arguement takes in a byte, WTF can I put into there? Im asking for Java, and C++. My server is programmed in Java (its a robot, and it uses java...) and the client is in C++, so will it have problems when sending and receiving a socket with ints or floats and doubles? They don't have the same "standards" from what I know, or is it just better to send a giant string? I am trying to transfer an array of doubles to the PC from the robot through sockets. IDK if I should send the values one by one and check if they are the same and then send the other one or not check at all?
I am trying to render a 3d image captured from the robot on the client PC's screen using OpenGL and SDL. I got the getting the image part down, and the drawing part, but not the communication, which is one vital factor that can render this useless.
I am trying to render a 3d image captured from the robot on the client PC's screen using OpenGL and SDL. I got the getting the image part down, and the drawing part, but not the communication, which is one vital factor that can render this useless.
Re: Question On Bytes and Sockets
a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)davidthefat wrote:So exactly what is a byte? IDK how to ask this, but is it a hex? or binary? or what? When the arguement takes in a byte, WTF can I put into there? Im asking for Java, and C++. My server is programmed in Java (its a robot, and it uses java...) and the client is in C++, so will it have problems when sending and receiving a socket with ints or floats and doubles? They don't have the same "standards" from what I know, or is it just better to send a giant string? I am trying to transfer an array of doubles to the PC from the robot through sockets. IDK if I should send the values one by one and check if they are the same and then send the other one or not check at all?
I am trying to render a 3d image captured from the robot on the client PC's screen using OpenGL and SDL. I got the getting the image part down, and the drawing part, but not the communication, which is one vital factor that can render this useless.
a nibble is half a byte, so 4 bits.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Re: Question On Bytes and Sockets
Thanks I can always rely on you, so I can just send raw Binary or Hex though it?avansc wrote: a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: Question On Bytes and Sockets
You can't send raw binary or hex through it, binary and hex are just a way of viewing the data.. You can send bytes though. Open up your calculator and you can see this, a number can be viewed in base 2 (binary) base 10 (decimal) or base 16 (hexadecimal) however the data, no matter how your viewing it, is the same. recap: you send bytes, you can view those bytes in binary, hex, whatever.davidthefat wrote:Thanks I can always rely on you, so I can just send raw Binary or Hex though it?avansc wrote: a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Re: Question On Bytes and Sockets
I see, I was just confusing my self, I can just send a string or a int or other primitive types through a socketshort wrote:You can't send raw binary or hex through it, binary and hex are just a way of viewing the data.. You can send bytes though. Open up your calculator and you can see this, a number can be viewed in base 2 (binary) base 10 (decimal) or base 16 (hexadecimal) however the data, no matter how your viewing it, is the same. recap: you send bytes, you can view those bytes in binary, hex, whatever.davidthefat wrote:Thanks I can always rely on you, so I can just send raw Binary or Hex though it?avansc wrote: a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: Question On Bytes and Sockets
Yes, you can.
If you send a byte through (an unsigned char) which has a value of 255, really you are sending 1111 1111 over the network. The hex representation of that is FF. It's just another way to look at the same data. You can send the "hex" representation as a char array, but thats two bytes. unsigned char[2] = 'F', 'F'. It's slower to transmit and you have to encode it and de-encode it.
Just send it as binary. It's far quicker obviously
1111 1111 is FF is 255. They are exactly the same.davidthefat wrote:Thanks I can always rely on you, so I can just send raw Binary or Hex though it?avansc wrote: a byte is just a word that means 8 sequential bits. the byte int binary 1111 1111 is FF in hex and 255 in decimal (unsigned of course.)
a nibble is half a byte, so 4 bits.
If you send a byte through (an unsigned char) which has a value of 255, really you are sending 1111 1111 over the network. The hex representation of that is FF. It's just another way to look at the same data. You can send the "hex" representation as a char array, but thats two bytes. unsigned char[2] = 'F', 'F'. It's slower to transmit and you have to encode it and de-encode it.
Just send it as binary. It's far quicker obviously
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Re: Question On Bytes and Sockets
Seems like I was looking at the parent classes, I went down the "family tree" and found the class I needed, it has everything from int to float and doubles
Re: Question On Bytes and Sockets
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completenessavansc wrote: a byte is just a word that means 8 sequential bits.
- Milch
- Chaos Rift Junior
- Posts: 241
- Joined: Sat Jul 11, 2009 5:55 am
- Programming Language of Choice: C++
- Location: Austria, Vienna
Re: Question On Bytes and Sockets
I think ANSI-C99 reads that a byte are ATLEAST 8 bitsK-Bal wrote:The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completenessavansc wrote: a byte is just a word that means 8 sequential bits.
Follow me on twitter!
Re: Question On Bytes and Sockets
Ummm.. wel i might be wrong here, but as far as i know a byte is a byte. It is always 8 bits on any arch.K-Bal wrote:The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completenessavansc wrote: a byte is just a word that means 8 sequential bits.
a word is USUALLY half of what a int is. which is 2 bytes or 16 bits on most archs. "short" is a synonym for word.
you can test it out if you want, printf("%d\n", sizeof(short)); printf("%d\n", sizeof(int));
if you program in asm you actually use "word", DW for a word in x86 asm.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: Question On Bytes and Sockets
Most platforms are 8bits/byte, but not all.avansc wrote:Ummm.. wel i might be wrong here, but as far as i know a byte is a byte. It is always 8 bits on any arch.K-Bal wrote:The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completenessavansc wrote: a byte is just a word that means 8 sequential bits.
http://en.wikipedia.org/wiki/Byte
It is however not so simple.The byte (pronounced /ˈbaɪt/) is a unit of digital information in computing and telecommunications. It is an ordered collection of bits, in which each bit denotes the binary value of 1 or 0. Historically, a byte was the number of bits (typically 5, 6, 7, 8, 9, or 16) used to encode a single character of text in a computer and it is for this reason the basic addressable element in many computer architectures. The size of a byte is typically hardware dependent, but the modern de facto standard is 8 bits, as this is a convenient power of 2. Most of the numeric values used by many applications are representable in 8 bits and processor designers optimize for this common usage. Signal processing applications tend to operate on larger values and some digital signal processors have 16 or 40 bits as the smallest unit of addressable storage (on such processors a byte may be defined to contain this number of bits). The term octet was explicitly defined to denote a sequence of 8 bits because of the ambiguity associated with the term byte and is widely used in communications protocol specifications.
The C and C++ programming languages, for example, define byte as "addressable unit of data large enough to hold any member of the basic character set of the execution environment" (clause 3.6 of the C standard). The C standard requires that the char integral data type is capable of holding at least 255 different values, and is represented by at least 8 bits (clause 5.2.4.2.1). Various implementations of C and C++ define a byte as 8, 9, 16, 32, or 36 bits. The actual number of bits in a particular implementation is documented as CHAR_BIT as implemented in the limits.h file. Java's primitive byte data type is always defined as consisting of 8 bits and being a signed data type, holding values from −128 to 127.