How to build a web-based chat system using ruby Gserver

a 夏天 提交于 2020-01-04 14:29:17

问题


I am trying to build a web based chat system and I am going to user ruby gserver. I have looked at this example . However my question is when I get the user input from the web and in the controller I have the user input. Now how does client connect to server to pass this user input value to the server.

The server after getting the value will populate a database. So the client will do all read operations from database. However I was wondering how will client connect to server. It is a simple question but I could not figure it out.


回答1:


Now, I'm making some massive assumptions, because your question is as vague as hell.

Assumption 1: You are running the chatserver pretty much unmodified
Assumption 2: You are running the web service and the chat server on the same host

In that case, you can connect to the chat server using the socket libs, and send it data that way.

require 'socket'
include Socket::Constants
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( 1234, 'localhost' )
socket.connect( sockaddr )
socket.write( "foo\nquit\n" )
puts socket.read
socket.close

This will send "foo" to the chat server, and then close the connection



来源:https://stackoverflow.com/questions/1838149/how-to-build-a-web-based-chat-system-using-ruby-gserver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!