5 Replies Latest reply: Sep 9, 2011 10:41 PM by jschellSomeoneStoleMyAlias RSS

    Socket programming

    880368
      Hello,
      I have a newbie question. I do apologize if I ask very ignorant questions. Why do we need socket programming. Can we acheive the same using web based programming. If the input for an application is coming as bits and bytes using tcp/ip then can we convert the input to character based and also can we use some other communication protocol.

      Thanks,
        • 1. Re: Socket programming
          DrClap
          Sockets are how data is transmitted across networks, at least TCP/IP-based networks. (You aren't likely to use any other kind of network.) They are a low level of communication architecture so the user is normally unaware that they are being used. But HTTP, FTP, and anything else you can think of is actually using sockets to communicate.

          So in one sense you need socket programming because that's the only way to get data from one computer to another. But in another sense you don't need it, because you're using a higher-level kind of programming which hides the sockets under the covers.

          All of which means your question is somewhat meaningless, as you may have suspected. There isn't a choice between web-based programming and socket programming. There IS a choice between HTTP and FTP and some other communication protocol which you might invent.
          • 2. Re: Socket programming
            801313
            877365 wrote:
            Hello,
            I have a newbie question. I do apologize if I ask very ignorant questions. Why do we need socket programming. Can we acheive the same using web based programming.
            Answer: No, not really.

            Furthermore, how you have web based programming without a socket layer? It makes no sense.
            If the input for an application is coming as bits and bytes using tcp/ip then can we convert the input to character based and also can we use some other communication protocol.
            Um, like <i>HTTP</i> yes of course.
            >
            Thanks,
            • 3. Re: Socket programming
              880368
              Thanks for your replies. Here is something I am considering...if an application written in another language recieves input as packets with bytes(it has header and data info stored) and I would like to convert this application to Java. I have no concept of socket programming but normally I recieve input as String or other variables rather than packets (the underlying protocol must be taking the raw format and converting to String etc). When I convert this application to Java, do I still have to accept the input as packets and process it. For example the packets currently has information regarding employee name and the response has further details regarding the employee. Do I need socket programming in Java to read these input packets..or do they need to be converted to high level String or any other. Again pardon my ignorance.
              • 4. Re: Socket programming
                DrClap
                When you convert the application to Java, that doesn't make the input format change, right? That's one of your requirements. So you'll have to write Java code which processes input in that format.

                If the existing application is using socket programming then yes, your Java conversion is going to have to do the same thing.

                I don't know what all that business about String is in your question. Especially the concept of "high-level String" which is laughable. A String is one of the lowest-level concepts in the Java language. But anyway if you have no concept of socket programming there's no way you would be able to even understand that application, let alone rewrite it in Java. So I suggest you fix that deficiency first.
                • 5. Re: Socket programming
                  jschellSomeoneStoleMyAlias
                  877365 wrote:
                  Thanks for your replies. Here is something I am considering...if an application written in another language recieves input as packets with bytes(it has header and data info stored) and I would like to convert this application to Java. I have no concept of socket programming but normally I recieve input as String or other variables rather than packets (the underlying protocol must be taking the raw format and converting to String etc). When I convert this application to Java, do I still have to accept the input as packets and process it. For example the packets currently has information regarding employee name and the response has further details regarding the employee. Do I need socket programming in Java to read these input packets..or do they need to be converted to high level String or any other. Again pardon my ignorance.
                  You are mixing concepts.

                  TCP/IP uses packets to move data across a network. I doubt you need to concern yourself with packets except to the extent that you must understand that the mechanism exists solely to move the data. The data is what you care about.

                  The form that the data takes is up to you. It has nothing to do with TCP/IP.

                  As an example of that HTTP is a protocol that is built on top of TCP/IP. There are specifications that define how client and servers work that use HTTP both in how they act in regards to sending and receiving and what the contents of the data that is transported.


                  To use TCP/IP you must define what format your data will take. You might choose to use a protocol that is already built on top of it or create your own.

                  If you create your own I suggest strongly that you strictly demarcate the difference between 'message' and 'data' in that you send a 'message' which contains your 'data'. At a minimum a 'message' should provide a mechanism that specifies how long (bytes) the 'data' is. Your data can take any form that you wish.