如何使用ruby Gserver构建基于Web的聊天系统 [英] How to build a web-based chat system using ruby Gserver

查看:68
本文介绍了如何使用ruby Gserver构建基于Web的聊天系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个基于Web的聊天系统,并且我将使用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 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.

推荐答案

现在,我正在做一些大的假设,因为您的

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

假设1:您正在运行的聊天服务器几乎未修改

假设2:您正在运行Web服务,并且在同一主机上的聊天服务器

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

这会将 foo发送到聊天服务器,然后关闭连接

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

这篇关于如何使用ruby Gserver构建基于Web的聊天系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆