开发者

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

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 c开发者_开发问答ontroller 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜