首页IT科技even though though although的区别(Geventsocketio documentation — geventsocketio 0.3.1 documentation)

even though though although的区别(Geventsocketio documentation — geventsocketio 0.3.1 documentation)

时间2025-05-03 02:03:38分类IT科技浏览3709
导读:Gevent-socketio documentation¶...

Gevent-socketio documentation¶

Concepts¶

In order to understand the following documentation articles, let’s

clarify some of the terms used:

A Namespace

is like a controller in the MVC world. It encompasses

a set of methods that are logically in it. For example, the

send_private_message event would be in the /chat

namespace, as

well as the kick_ban event. Whereas the scan_files

event

would be in the /filesystem

namespace. Each namespace is

represented by a sub-class of BaseNamespace

. A simple

example would be, on the client side (the browser):
var socket = io.connect("/chat");

having loaded the socket.io.js

library somewhere in your .

On the server (this is a Pyramid example, but its pretty much the same

for other frameworks):
from socketio.namespace import BaseNamespace class ChatNamespace(BaseNamespace): def on_chat(self, msg): self.emit(chat, msg) def socketio_service(request): socketio_manage(request.environ, {/chat: ChatNamespace}, request) return "out"

Here we use socketio.socketio_manage()

to start the Socket.IO

machine, and handle the real-time communication.

You will come across the notion of a Socket

. This is a virtual

socket, that abstracts the fact that some transports are long-polling

and others are stateful (like a Websocket), and exposes the same

functionality for all. You can have many namespaces inside a Socket,

each delimited by their name like /chat, /filesystem

or

/foobar

. Note also that there is a global namespace, identified

by an empty string. Some times, the global namespace has special

features, for backwards compatibilty reasons (we only have a global

namespace in version 0.6 of the protocol). For example, disconnecting

the global namespace means disconnect the full socket. Disconnecting

a qualified namespace, on the other hand, only removes access to that

namespace.

The Socket

is responsible from taking the packets, which are, in

the realm of a Namespace or a Socket

object, a dictionary that

looks like:
{"type": "event", "name": "launch_superhero", "args": ["Superman", 123, "km", {"hair_color": "brown"}]}

These packets are serialized in a compact form when its time to put

them on the wire. Socket.IO also has some optimizations if we need to

send many packets on some long-polling transports.

At this point, if you don’t know gevent

, you probably will want to

learn a bit more about it, since it is the base you will be working

on:
http://www.gevent.org/

Getting started¶

Until we have a fully-fledged tutorial, please check out our example

applications and the API documentation.

See this doc for different servers integration:

Server integration layers

Examples¶

The gevent-socketio holds several examples:

https://github.com/abourget/gevent-socketio/tree/master/examples

chat.py is a bare-bone WSGI app with a minimal socketio integration

chatter2 is a simple chat application, showing off the minimal setup

chatter3 is an app using socket.io, backbone.js and redis for pubsub

chatter4 is chatter3 with persistence added.

testapp is the app we use to test the different features, so there

are a couple of more advanced use-cases demonstrated there

pyvore

is an application that was developed to serve as real-time

chat in conferences like the PyCon:
https://github.com/sontek/pyvore

This app is a Django tic-tac-toe application that uses the latest

gevent-socketio:
https://github.com/sontek/django-tictactoe

API docs¶

http://www.gevent.org/
Server integration layers

https://github.com/abourget/gevent-socketio/tree/master/examples

chat.py is a bare-bone WSGI app with a minimal socketio integration

chatter2 is a simple chat application, showing off the minimal setup

chatter3 is an app using socket.io, backbone.js and redis for pubsub

chatter4 is chatter3 with persistence added.

testapp is the app we use to test the different features, so there

are a couple of more advanced use-cases demonstrated there

https://github.com/sontek/pyvore
https://github.com/sontek/django-tictactoe
声明:本站所有文章           ,如无特殊说明或标注                 ,均为本站原创发布            。任何个人或组织      ,在未征得本站同意时      ,禁止复制            、盗用                 、采集     、发布本站内容到任何网站            、书籍等各类媒体平台                 。如若本站内容侵犯了原著者的合法权益                 ,可联系我们进行处理     。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
python如何导入包(python包的导入方式有几种) 鸡西权威发布(鸡西门户网)