ruby - How to implement a tcp socket in a rails app? -


i'm complete beginner rails , web development in general. i'm looking implement ruby tcpsocket server in rails application recieve data client on raw tcp connection without http protocol. app have other functionality handled rails. possible? example simple server can run on computer:

require 'socket'                 server = tcpserver.new 3490   puts "waiting connection" client = server.accept   puts "client found"                          while str=client.recv(100);           val=str.unpack("h*")     temp=val.join('').gsub('0','').to_i  #application specific code below     if temp<100         temp=temp*10     end     print "temperature: "     puts temp*0.125  end 

how can implement in rails app? kind of suggestions appreciated.

rails rack application, per rails documentation,

rails.application primary rack application object of rails application. rack compliant web server should using rails.application object serve rails application.

since rack wraps http requests , responses, 1 may not able build pure tcp ip socket based interaction rails server.

however, may want have @ action cable, new addition rails 5 - integrates websockets rails application. per wikipedia,

the websocket protocol independent tcp-based protocol. relationship http handshake interpreted http servers upgrade request.

how extract action cable work non browser clients may tricky given rails web application framework.


Comments