sockets - how to use the ruby analytical receive binary stream from the TCP -


I am going to the device received on data, but these data are binary streams, I keep these data collections, then Read it to display them correctly, is there a better way?

  requires a 'socket' server = TCPA.org.open (2000) loop {thread.start (server.accept) do. Client | File.open ("tmp", "w") {| File | File.write (client.gets)} file.open ("tmp"). Every do F | | Puts f.unpack ('h *') end client.puts (Time.now.ctime) # Send time to customer customer. Line "connection closed. Bye!" Client.close # Disconnect from the end of the customer}   

Received data like this: xx ^ q ^ a ^ hb0 @ lt; 90 & gt; 26 2 ^ b ^ @ & lt; 83 & gt; Ev

I would like to: 787811010862304020903236202032020001c26c0d0a

Sorry for my poor English ??

Using a temporary file with a name will cause a problem if many clients are sending data Are; The temporary file will overwrite.

You do not need to use a temporary file.

  Requires a 'socket' server = TCPA.org.Open (2000) loop {thread.start (server.accept). Customer | Client.gets.unpack puts ('h *') client.puts (time.now.ctime) # Send time to client client. "Close the connection. Bye!" Client.close end}    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -