Question On Bytes and Sockets

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
davidthefat
Chaos Rift Maniac
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

Post by davidthefat »

So exactly what is a byte? :lol: 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.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Question On Bytes and Sockets

Post by avansc »

davidthefat wrote:So exactly what is a byte? :lol: 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 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.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
davidthefat
Chaos Rift Maniac
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

Post by davidthefat »

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.
;) Thanks I can always rely on you, so I can just send raw Binary or Hex though it?
User avatar
short
ES Beta Backer
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

Post by short »

davidthefat wrote:
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.
;) Thanks I can always rely on you, so I can just send raw Binary or Hex though it?
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.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
davidthefat
Chaos Rift Maniac
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

Post by davidthefat »

short wrote:
davidthefat wrote:
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.
;) Thanks I can always rely on you, so I can just send raw Binary or Hex though it?
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.
I see, I was just confusing my self, I can just send a string or a int or other primitive types through a socket
Live-Dimension
Chaos Rift Junior
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

Post by Live-Dimension »

Yes, you can.
davidthefat wrote:
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.
;) Thanks I can always rely on you, so I can just send raw Binary or Hex though it?
1111 1111 is FF is 255. They are exactly the same.

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 ;)
Image
User avatar
davidthefat
Chaos Rift Maniac
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

Post by davidthefat »

:lol: 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
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Question On Bytes and Sockets

Post by K-Bal »

avansc wrote: a byte is just a word that means 8 sequential bits.
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completeness ;)
User avatar
Milch
Chaos Rift Junior
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

Post by Milch »

K-Bal wrote:
avansc wrote: a byte is just a word that means 8 sequential bits.
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completeness ;)
I think ANSI-C99 reads that a byte are ATLEAST 8 bits :)
Follow me on twitter!
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Question On Bytes and Sockets

Post by avansc »

K-Bal wrote:
avansc wrote: a byte is just a word that means 8 sequential bits.
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completeness ;)
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.

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"
Live-Dimension
Chaos Rift Junior
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

Post by Live-Dimension »

avansc wrote:
K-Bal wrote:
avansc wrote: a byte is just a word that means 8 sequential bits.
The standard just tells that a byte is the smallest word. It does not tell how much bits it has. Just for completeness ;)
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.
Most platforms are 8bits/byte, but not all.

http://en.wikipedia.org/wiki/Byte
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.
It is however not so simple.
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.
Image
Post Reply