Problem

23 views
Skip to first unread message

Keith Sammut

unread,
Mar 29, 2012, 9:47:34 AM3/29/12
to SystemsProgramming2011_12
Hi Sir,

We are trying to send our map from the server to the client. The map
is a 2D int array of 40 by 100.
The map is being received all locally, however when we tried from one
PC to another, only a small part of the map is being received. Any
suggestions please?

Thank you,
Keith & Luke

Joseph Cordina

unread,
Mar 31, 2012, 5:06:26 AM3/31/12
to systemsprogr...@googlegroups.com
Hi,
  remember that the write is not guaranteed to receive the whole region in one call. write() always returns the number of bytes it managed to read. To get around this problem you need to write a reliable write (which we covered in lectures). Also since you are sending integers, keep network byte ordering in mind.

Regards

Joseph Cordina

ad

unread,
May 9, 2012, 7:35:04 AM5/9/12
to SystemsProgramming2011_12
Hi sir,

I was wondering whether since we're using TCP, are issues of network
byte ordering handled implicitly through this protocol? Or should this
be explicitly invoked?

Regards,

Adrian

Joseph Cordina

unread,
May 9, 2012, 3:40:15 PM5/9/12
to systemsprogr...@googlegroups.com
Hi,

network byte ordering has to be handled explicitly and will not happen automatically.

Regards

Joseph Cordina

ad

unread,
May 9, 2012, 3:59:32 PM5/9/12
to SystemsProgramming2011_12
Thank you sir

Ivan

unread,
May 11, 2012, 9:18:45 AM5/11/12
to systemsprogr...@googlegroups.com
Hi Sir,

Would it be portable to send messages over a network, where the message is a struct with members using bit fields?
For example:
struct Message {
A :4;
B :4;
}

The idea was to optimize the message size but I'm concerned if compiler optimizations on the size of the struct might result with different machines holding the message with a different size on each machine and thus corrupting the communication between the machines.


Regards,
Ivan Galea

Joseph Cordina

unread,
May 12, 2012, 1:57:39 AM5/12/12
to systemsprogr...@googlegroups.com
Hi,
  as long as you keep your struct to be equal or less than 8 bits, you should be fine since all CPUs store 8 bits in the same format (more or less). YET if you make a struct larger than 8 bits then you have the problem of network byte ordering etc ! Its a good trick for optimization though

Regards

Joseph Cordina

Ivan

unread,
May 12, 2012, 11:01:41 PM5/12/12
to systemsprogr...@googlegroups.com
Would it be possible to use the ntohs and htons function on members of a struct with bit fields? Or must those functions be used only on normal unsigned short?


Thanks,
Ivan Galea

Joseph Cordina

unread,
May 13, 2012, 5:58:43 AM5/13/12
to systemsprogr...@googlegroups.com
Hi,
  I would be careful using those functions on bit sets since different compilers might package bit sets larger than 8 bits in a different way. Again I would really not use bit sets for anything larger than 8 bits

Regards

Joseph Cordina

Ivan

unread,
May 13, 2012, 5:30:15 PM5/13/12
to systemsprogr...@googlegroups.com
Ok thanks.
Reply all
Reply to author
Forward
0 new messages