Forgot your password?
typodupeerror
Programming

jawtheshark's Journal: Java vs C for network connections. 27

Journal by jawtheshark

Well, for now I'm still programming some C at work. At least it's a bit motivating. Now, for the thing I need to make, I need a network connection and thus use sockets. I was initially a bit scared of it, because I've never done network programming in C. Besides, back when Java was launched, the word was that "nerworking is so much simpeler on Java" so I was naturally a bit scared.

Frankly, that's a load of bullshit. Creating and communicating over sockets in C is really straighforward and easy. Okay, it took a while before I found the shutdown function, but everything has got a learning curve. Frankly, the way sockets work in C feels much more natural than what Java does and I've been programming Java for 10 years.

That itching on my chin must be my greybeard that starts to grow ;-)

This discussion has been archived. No new comments can be posted.

Java vs C for network connections.

Comments Filter:
  • Yeah, I learned socket programming on UNIX in C. Piece of cake. Java has a bunch of (unnecessary, if you ask me) wrappers. Convolutes things, if you ask me. Although, I have to say the new 'executor' classes for async threading in java makes network programming interesting.
    • Haven't used the "executor" classes yet... Will need to look into that.
    • Care to give some examples? I'm getting ready to start delving into this now ...
      • by FortKnox (169099) *
        What, C network programming, Java network programming, or async threading?
        • C) All of the above. Mostly reverse engineering things that were created using the above methods but going forward is a good start.
          • by Tet (2721) *
            For C network programming, start here [kohala.com]. I can't help with Java network programming. I'm not entirely sure what "async threading" might refer to. Async IO is one thing. Threading is another. Async IO using threads? Maybe. Avoiding shared data structures (and hence locks) between threads? Perhaps. It's good practice, but it's not really asynchronous. Unless you're abusing the Java "synchronized" terminology, I suppose...
            • by FortKnox (169099) *
              I'm sure I'm using the wrong terminology. Its how I think of it in my head. "Concurrent Threading" I think is the appropriate terminology. In java its a pain to work with multiple threads, shutting them down, etc... The executor classes make things like worker threads and thread pooling a piece of cake.
          • by FortKnox (169099) *
            Email me on what you want to see (like an echo server or something), and I can whip up a java program to do it. Been a while since I was in C, though... you may be better asking someone else about that.
            • Been a while since I was in C, though... you may be better asking someone else about that.

              One of the examples I found online for C socket programming was indeed an echo server and client. That was one of the better ones. I have the bookmark at work, will try to add it to this thread if I think of it tomorrow.

            • As promised [villanova.edu]
              • by FortKnox (169099) *
                Yeah, echo server is a common 'simple' case, but its using 'listen' which is blocking IO (won't continue on until something comes into the socket). Wish they had an example with 'poll' which is non-blocking IO...
  • Trying to treat a socket as an object has to be one of the more painful experiences of my life. I was once upon a time trying to create a telnet clone in java....without any pattern experience. I now know I should have been using MVC for what I was trying to do, but at the time I was just bulling forward through the code. No love for the "Java Cookbook" author who wrote a "telnet client" that was not a telnet client--it was a simple socket client, not even close.
    • So, you're also getting a grey beard? ;-) I was so amazed by the pure C that I'd love to stay in that language. No luckin hell will bring me that :-(
      • by Tet (2721) *

        I was so amazed by the pure C that I'd love to stay in that language.

        I knew you'd see the light eventually :-) I've never done any network programming in Java, but yes, it's easy in C. New alternatives may come along every so often, but C remains to this day my favourite programming language.

        • Well, I'll need luck to find a job doing that exclusively ;-) Who knows, this project might be the beginning of a new C career.
    • My experience (which has little to do with the language proper and more with an application) was trying to figure out how a popular open source application server boots up.
      Delving into the guts, it appeared that there was an XML parser, and this app server was digesting all of the XML configuration files at boot-time, then using reflection to generate all of the security realm stuff for the server.
      I just figured that something about the Java community encourages relatively more self-flagellation than any
      • Thoughts?

        I just figured that something about the Java community encourages relatively more self-flagellation than any other group of folks I've encountered.

        My reply: True. I say this as a 10 year Java developer. Telling people their solutions are crap because over-complication (and introspection is one of the biggies in that!). Nobody ever listens to me.

  • Seriously folks. Java's sockets are incredibly more straightforward to use. They may be less explicit in terms of flexibility and options, but they rock in terms of getting your code networked. And Java's excellent threading is helping out here, too!

    I've actually done Java to C/C++ networking and I can tell you that being able to write platform oblivious code is such a treat! On the other hand, it's quite a challenge to match the same socket setup in C and get a decent connection going.

    That said, I'm writin
    • Yes, I loved Java sockets in the beginning, but frankly the C way just seemed so much more simple. To get it done fast, Java is the way, to have more control C is better.

      For threading: yes absolutely. However, you don't *need* threading for sockets. It's nice to have both, but in the context I needed it, a single thread was more than enough.

You are in a maze of little twisting passages, all alike.

Working...