Berkeley CSUA MOTD:Entry 10768
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/07/08 [General] UID:1000 Activity:popular
7/8     

2003/10/24-25 [Computer/SW/Mail, Computer/SW/Compilers] UID:10768 Activity:nil
10/24   Are there any pitfalls involved in using sendmsg/recvmsg over
        send/recv?  I finally got my problems solved with basic sockets,
        and I'm looking for a good way to say "these bytes are msg1,
        these are msg2" etc.  Thanks
        \_ These are two separate issues.  (1) man sendmsg.  (2) Since
           TCP is byte-stream oriented, you will need to introduce some
           message delimiting mechanism.  Common ways are LF (like SMTP,
           POP3, BGP) and having predictable message lengths
           (e.g., constant for all messages, having an early size field
           which indicates the size of the message, having an early type
           field which you associate with a given size, etc.).
           http://tangentsoft.net/wskfaq/articles/effective-tcp.html
           \_ Thanks for the link.  I've been using a length-header so
              far, but I was thinking that perhaps MSG_EOR would be a
              better solution.  I can't use the delimiter option b/c the
              module must also handle binary data, and I have no
              guarantees on length either.  I guess I'll stick w/ what
              works.
              \_ You can come up with a prefix code for your
                 messages.  This can be a good idea for reasons other than
                 getting rid of delimiters (since a good prefix code will
                 compress what you send over the wire). -- ilyas
                 \_ I thought you had to have a known alphabet to do that.
                    And the binary data is totally unknown.
                    \_ If it's binary data, the alphabet is {0, 1},
                       by definition. -- ilyas
                        \_ kinda hard to compress 1 & 0, isn't it?
                           \_ I think you are unclear on the concept.  Files
                              you compress with gzip are 1s and 0s, and they
                              compress just fine.  -- ilyas
                              \_ I understand the concept, but if you can't
                                 predict the expected distribution of your
                                 data (even at the byte level) you probably
                                 won't achieve much compression-- yes, I'll
                                 probably get some compression just by using
                                 a standard english distribution, but not
                                 enough to make it worthwhile.  You are
                                 correct in the technical sense, but it's not
                                 enough to break what works right now.
                                 \_ Sure you will.  It's what universal source
                                    coding is all about.  Why do you think it
                                    works on files, where we can't predict
                                    the distribution either?  At any rate, the
                                    original point of using a prefix code in
                                    your case was to get rid of delimiters.
                                    The compression (which will occur to
                                    entropy in the limit, trust me) is just a
                                    pleasant side effect.  -- ilyas
ERROR, url_link recursive (eces.Colorado.EDU/secure/mindterm2) 2025/07/08 [General] UID:1000 Activity:popular
7/8     

You may also be interested in these entries...
2012/10/15-12/4 [Computer/SW/Mail] UID:54501 Activity:nil
10/15   What's the soda email client these days?
        \_ Don't know.  /usr/bin/mail hasn't been working for a while.
        \_ forward to Gmail.
        \_ mutt works for me
	...
2012/8/29-11/7 [Computer/SW/Security] UID:54467 Activity:nil
8/29    There was once a CSUA web page which runs an SSH client for logging
        on to soda.  Does that page still exist?  Can someone remind me of the
        URL please?  Thx.
        \_ what do you mean? instruction on how to ssh into soda?
           \_ No I think he means the ssh applet, which, iirc, was an applet
              that implemented an ssh v1 client.  I think this page went away
	...
2011/11/14-30 [Computer/SW/Security] UID:54228 Activity:nil
11/14   Social Engineering call centers:
        http://www.itbusiness.ca/it/client/en/home/News.asp?id=64887
	...
2011/2/14-4/20 [Computer/SW/Unix] UID:54039 Activity:nil
2/14    You sure soda isn't running windows in disguise?  It would explain the
        uptimes.
        \_ hardly, My winbox stays up longer.
        \_ Nobody cares about uptime anymore brother, that's what web2.0 has
           taught us.  Everything is "stateless".
           \_ You;d think gamers would care more about uptime.
	...
2011/4/6-20 [Computer/SW/Mail, Computer/SW/Unix, Industry/Startup] UID:54078 Activity:nil
4/6     My company is evaluating version control systems. Our two candidates
        are Perforce and Subversion. Anyone worked with both and have good
        arguments one way or the other? (These are the only two options we
        have.) We're most interested in client performance, ease of use, and
        reasonable branching.
        \_ I'll be 'that guy'. If perforce and subversion are optins, why isn't
	...
2010/8/8-9/7 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Web] UID:53914 Activity:nil
8/8     Trying to make a list of interesting features languages have
        touted as this whole PL field comes around, trying to see if they
        have basis in the culture of the time: feel free to add some/dispute
        1970 C, "portability"
        1980 C++, classes, oop, iterators, streams, functors, templates
             expert systems
	...
2009/8/3-11 [Computer/HW/Laptop] UID:53235 Activity:low 70%like:53232
8/1     Where is the mac desktop going to go? It seems all the development
        in sw/hw now is for the iphone, imac.  2 finger Gestures won't work
        on the desktop.  What happened to the xserve line?
        \_ Two finger gestures DO work on the desktop.  Have you used a new
           Apple laptop lately...they support up to 5 finger gestures.
           \_ you're making my point even harder, do the 5 finger gestures
	...
2009/7/22-29 [Computer/SW/Mail] UID:53183 Activity:nil
7/22    How many people here use rss/atom, and how many people don't use it
        at all? If you use it, what client do you use? I'll start.
        \_ mix of google reader and safari subscription                 -kchang
        \_ I go to <DEAD>blogger.com<DEAD> and http://livejournal.com
        \_ I use NetNewsWire on mac.
	...
2009/4/26-29 [Computer/Networking] UID:52910 Activity:nil
4/25    I have an Airport Express.  is there some way to let computer
        1 ping computer 2?  both computers are connected to wireless network
        successfully.  I can get to internet on both of them.  I just can't
        ping each other.  weird.  maybe they think that's a feature?
        \_ Sounds like your router is enforcing client isolation. If you can't
           change the setting on the router you're probably SOL.
	...
2014/1/14-2/5 [Computer/SW/Languages/C_Cplusplus] UID:54763 Activity:nil
1/14    Why is NULL defined to be "0" in C++ instead of "((void *) 0)" like in
        C?  I have some overloaded functtions where one takes an integer
        parameter and the other a pointer parameter.  When I call it with
        "NULL", the compiler matches it with the integer version instead of
        the pointer version which is a problem.  Other funny effect is that
        sizeof(NULL) is different from sizeof(myPtr).  Thanks.
	...
2013/4/29-5/18 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Compilers] UID:54665 Activity:nil
4/29    Why were C and Java designed to require "break;" statements for a
        "case" section to terminate rather than falling-through to the next
        section?  99% of the time poeple want a "case" section to terminate.
        In fact some compilers issue warning if there is no "break;" statement
        in a "case" section.  Why not just design the languages to have
        termination as the default behavior, and provide a "fallthru;"
	...
2012/12/18-2013/1/24 [Computer/SW/Languages/Perl] UID:54561 Activity:nil
12/18   Happy 25th birthday Perl, and FUCK YOU Larry Wall for fucking up
        the computer science formalism that sets back compilers development
        back for at least a decade:
        http://techcrunch.com/2012/12/18/print-happy-25th-birthday-perl
        \_ I tried to learn Perl but was scared away by it.  Maybe scripting
           lanauages have to be like that in order to work well?
	...
2011/3/7-4/20 [Computer/SW/Languages/C_Cplusplus] UID:54056 Activity:nil
3/7     I have a C question.  I have the following source code in two identical
        files t.c and t.cpp:
                #include <stdlib.h>
                int main(int argc, char *argv[]) {
                  const char * const * p1;
                  const char * * p2;
	...
2010/1/22-30 [Computer/HW/Laptop, Computer/SW/OS/OsX] UID:53655 Activity:high
1/22    looking to buy a new development laptop
        needs ssdrive, >6 hr possible batt life, and runs linux reasonably
        Anyone have a recommendation? Thx.
        \_ thinkpad t23 w ssdrive and battery inplace of drive bay
        \_ Ever wondered what RICHARD STALLMAN uses for a laptop?  Well,
           wonder no more!
	...
2010/1/12-29 [Computer/SW/Apps/Media] UID:53627 Activity:kinda low
1/12    How do I get a job NOT related to internet DNS social network cloud
        twitter GOOG EC2 amazon API ???
        \_ A CS job not related to API?
        \_ Chip design, or maybe software that does chip design. What is
           your major? How about game developer?
        \_ DNS? DNS? What era ado you live in? I agree that social network
	...
2009/8/31-9/9 [Computer/SW/Compilers] UID:53312 Activity:nil
8/31    I'm trying to learn ActionScript, like a step by step tutorial.
        The site at http://www.actionscript.org/resources/categories/Tutorials/Flash/Beginner
        isn't well organized. It doesn't explain how to get started with
        an editor, compiler, IDE. And should I even learn AS2 when you can
        learn AS3? Is Adobe Flash CS4 >>> CS3 or just CS4 > CS3?
	...
2009/5/6-14 [Computer/SW/Languages/Perl, Computer/SW/Languages/Web] UID:52961 Activity:kinda low
5/6     I'm sure you've seen web sites that distribute software by making
        a user fill out a form and then e-mailing the user a randomly
        generate link to the software that works just once. What software
        is used to do this? I'd like to distribute software in such a way.
        \_ "Software"?  What web server/web application environment
           are you using?
	...
2009/2/28-3/11 [Computer/SW/Compilers] UID:52661 Activity:nil
2/28    I'm looking for a recommendation of a compiler/IDE to use to
        develop C/C++ code under Linux. In school, we used jove/gcc and
        I still use emacs/vi and gcc to this day. However, it is really
        lacking. Under Windows I tried Visual Studio and there were some
        really nice things about it, although it was so overwhelming that
        after 6 months of occasional use I still didn't really know what I
	...
2009/1/13-22 [Computer/Theory] UID:52367 Activity:kinda low
1/13    I am writing a commandline parser for a class and I could use some
        tips for algorithms to use. (The project is over and done so I am
        not cheating, but I am dissatisfied with my end result.) I STFW and
        didn't come up with too much I liked. I read the source for some
        shells like tcsh and that is *WAY* too complicated and relies on
        a lot of other code. I know that browsers and other apps have
	...
2008/6/9-12 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Security] UID:50194 Activity:nil
6/8     CSUA code guru please help. I need to see my random number
        generator with a good seed (I just need random 18 bit
        identifiers). The usual time(NULL) is OK, except my program
        might be invoked faster than once a second, and seeding using
        time() produced the same result. I tried clock() but it seems
        to return 0. My program needs to be run in Linux/DOS (Watcom
	...
Cache (4813 bytes)
tangentsoft.net/wskfaq/articles/effective-tcp.html
How to Use TCP Effectively by Warren Young Newcomers to network programming almost always run into problems early on where it looks like the network or the TCP/IP stack is munging your data. This usually comes as quite a shock, because the newcomer is usually told just before this that TCP is a reliable data transport protocol. In fact, TCP and Winsock are quite reliable if you use them properly. This tutorial will discuss the most common problems people come across when learning to use TCP. Problem 1: Packets Are Illusions This problem comes up in various guises: My client program sent 100 bytes, but the server program only got 50. My client program sent several small packets, but the server program received one large packet. How can I find out how many bytes are waiting on a given socket, so I can set up a receive buffer for the size of the packet? I think that understanding this issue is one of TCP/IPs rites of passage. The core concept that you must grasp is that TCP is a stream protocol. This means that if you send 100 bytes, the receiving end could receive all 100 bytes at once, or 100 separate single bytes, or four 25-byte chunks. Or, the receiver could receive that 100 byte block plus some data from the previous send and some from the succeeding send. So, you ask, how can you make a program receive whole packets only? For example, you could prefix every packet with a 2-byte unsigned integer that tells how long the packet is. Length prefixes are most effective when the data in each protocol packet has no particular structure, such as raw binary data. See this example for code that reads length-prefixed packets from a TCP stream. Another method for setting up packets on top of a stream protocol is called delimiting. Each packet you send in such a scheme is followed by a unique delimiter. There are a couple of other concerns for properly handling packets atop TCP. First, always check the return value of recv , which indicates how many bytes it placed in your buffer it may well return fewer bytes than you expect. Second, dont try to peek into the Winsock stacks buffers to see if a complete packet has arrived. Instead, read all the data directly into your applications buffers and process it there. Problem 2: Byte Ordering You have undoubtedly noticed all the ntohs and htonl calls required in Winsock programming, but you might not know why they are required. The reason is that there are two common ways of storing integers on a computer: big-endian and little-endian . Big-endian numbers are stored with the most significant byte in the lowest memory location big-end first, whereas little-endian systems reverse this. Obviously two computers must agree on a common number format if they are to communicate, so the TCP/IP specification defines a network byte order that the headers and thus Winsock all use. The end result is, if you are sending bare integers as part of your network protocol, and the receiving end is on a platform that uses a different integer representation, it will perceive the data as garbled. To fix this, follow the lead of the TCP protocol and use network byte order, always. The same principles apply to other platform-specific data formats, such as floating-point values. Winsock does not define functions to create platform-neutral representations of data other than integers, but there is a protocol called the External Data Representation XDR which does handle this. XDR formalizes a platform-independent way for two computers to send each other various types of data. For efficiency reasons, compilers pad structures to align the data members in a way that is convenient for the CPU. Most CPUs can access 32-bit integers faster if they are at addresses evenly divisible by 4, so the above structure would probably take up 12 bytes on these systems. This issue rears its head when you try to send a structure over Winsock whole, like this: sendsd, char&foo_instance, sizeoffoo, 0; Unless the receiving program was compiled on the same machine architecture with the same compiler and the same compiler options, you have no guarantee that the other machine will receive the data correctly. The solution is to always send structures packed by sending the data members one at a time. You can force your compiler to pack the structures for you, with a resulting speed penalty in the code that accesses those structures. Visual C can do this with the /Zp command line option or the pragma pack directive, and Borland C can do this with the -a command line option. Keep the byte ordering problem in mind, however: if you send a packed structure in place, be sure to reorder its bytes properly before you send it. The Moral of the Story Trust Winsock to send your data correctly, but dont assume that it works the way you think that it ought to!