Results 1 to 7 of 7
  1. #1
    zeyneqp is offline Member
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    Default to send float array with TCP socket

    Hi,
    I try to send a float array with TCP socket, but unfortunately, I can not do that. my server is c++, and my client is writen with java applet. they can send string each other but not send float, or array. please, can anybody help??

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    I can not do that.
    Can you explain why?
    If your communication is only String and has no binary capability, you will have to convert the floats to String and have an agreement/protocol with the server code so it knows what it is receiving and how to handle it.
    Are you sure you can't sent binary?
    If you send binary, the server will have to know how to reconstruct the data back into useful info.

  3. #3
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Over TCP/IP, you sent bytes. Its the rule.

    It is really a bad idea to send float or int, as you need to be sure that both sides interpret the bytes and bits the same. Google big endian and little endian for examples.

    Corba and other complex systems are about marshalling and unmarshalling binary things so they are understood on both ends. Of course Corba is complex and arcane itself.

    Advice: move string representations. Convert to and from binary as needed.

  4. #4
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    Novadays it is possible to use string-based JSON format. There are bunch of libraries for any programming language.

    Ref www dot json dot org

  5. #5
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by ProjectKaiser View Post
    Novadays it is possible to use string-based JSON format. There are bunch of libraries for any programming language.
    OK, I'll buy that JSON is the new cool Corba, but I still don't understand any need to send binary over a network when you can just send text messages. Its a thousand times easier to debug.

  6. #6
    Join Date
    Aug 2008
    Location
    Saint-Petersburg, Russia
    Posts
    66
    Rep Power
    0

    Default

    Why binary ? JSON produces human-readable text stream. Advantage is that you do not need to write your own serialization/deserialization code - this is what JSON library does for some primitive types and objects.
    Last edited by ProjectKaiser; 08-29-2008 at 10:52 PM.

  7. #7
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by ProjectKaiser View Post
    Why binary ? JSON produces human-readable text stream.
    All it is doing is seralizing it for you. If you are sending an int or float, you are sending binary. As you say, JSON can marshal it for you.

    But I believe its a weak design to send binary when you can simply send text messages. You can send text with two or three lines of simple Java, no libraries, no API, nothing fancy. To me, this is much better.

    YMMV

Similar Threads

  1. Server socket - send image to client
    By Hinty in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 07:39 AM
  2. Send an array via Socket
    By lene in forum Networking
    Replies: 0
    Last Post: 04-23-2008, 04:29 PM
  3. String to Float
    By durahman in forum New To Java
    Replies: 2
    Last Post: 02-12-2008, 12:17 AM
  4. Float to String
    By mew in forum New To Java
    Replies: 4
    Last Post: 12-29-2007, 05:08 PM
  5. send files through socket
    By bbq in forum Advanced Java
    Replies: 1
    Last Post: 06-05-2007, 02:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •