Php + websocket Simple Chat Room practice, websocket Construction
1. Preface
There is a simple chat room in the company's game. After learning about it, I learned that it was implemented by node + websocket. I think php will also be used as a
Websocket protocol details and simple instance code, websocket details examples
Websocket protocol details
For more information about the websocket protocol, see other articles.
WebSocket keywords
HTML5 protocol, real-time, full-d
distributed Public classMessageHandlerextendsTextwebsockethandler {//Save user's WebSocket connectionPrivatemapNewHashmap(); protected voidHandletextmessage (websocketsession session, TextMessage message)throwsException {if(!"". Equals (Message.getpayload ())) session.sendmessage (message); } Public voidAfterconnectionestablished (websocketsession session)throwsException {//After connection is established, save user information and send login
. Use the Send () method to send a message to the server from the client. After sending one or more messages, you can leave the connection open or call the Close () method to terminate the connection.
Instance:
Ws.send ("Hello websocket!");
B, Close () method:
Using the Close () method, you can turn off the WebSocket connection or terminate the connection attempt. If the connection is closed,
Today, many Web sites are polled for the technology they use to implement push technology. Polling is at a specific time interval (such as every 1 seconds), the browser sends an HTTP request to the server, and then the server returns the latest data to the client's browser. This traditional pattern brings with it the obvious drawback that the browser needs to constantly make requests to the server, but the header of the HTTP request is very long, and the data contained in it may be a small value
. println (******* getAnnotatedEndpointClasses *******); // Deploy all WebSocket endpoints defined by annotations in the examples // web application. filter out all others to avoid issues when running // tests on Gump // This is mainly a scan class package, if the prefix is com. websocket. just grab her and then do what, you know Set
> Res = new HashSet Cs: scanned) {if (cs. getPackage (). getName
This article describes the PHP based on WebSocket to build a simple chat room practice. Share to everyone for your reference. Specifically as follows:1. Preface
There is a simple chat room in the company game, understand after know is node+websocket do, think of PHP also to do a s
This article mainly explains how to set up a simple chat room using php + websocket. for details about php and websocket, please refer to those who need it. This article mainly explains how to set up a simple chat room using php + websocket. for details about php and
This article mainly introduces a simple WebSocket server that is compatible with the old and new Socket protocols in Python, if you need it, you can refer to the WebSocket technology introduced in HTML5 that needs to be used in a recent project. I thought it would be easy to handle it, who knows that there are a lot of troubles after the development is really sta
generating handshake token, need to make a judgment." First look at the Safari,token generation algorithm using the old version protocol as follows:
Take out all the numeric characters in the Sec-websocket-key1 to form a number, here is 1427964708, then divide by the number of spaces in the Key1, this is like 6 spaces, get a numeric value, retain the value of the integer digits, get the value N1 , and Sec-websock
WebSocket is a simple demo program based on javaweb + tomcat, and websocketjavaweb
As required by the project, after the frontend initiates a request to the background, the background must be divided into multiple steps for relevant operations, and the time required for completing each step cannot be determined.
If ajax is used to repeatedly access the background to obtain real-time data, it is obviously no
Php uses websocket to build a simple chat room and phpwebsocket
This example describes how to set up a simple chat room in php Based on websocket. Share it with you for your reference. The details are as follows:1. Preface
There is a simple chat room in the company's game. A
to generate token is relatively simple: first of all, Sec-websocket-key and a series of fixed uuid "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" do stitching, and then the concatenation of the string do SHA1 encryption , after getting digest, do a base64 code, you can get token.
Also note that the new version and the old version of the handshake protocol back to the client data structure is different, in the att
complete the handshake.
The Token Generation Method of the new protocol is relatively simple: first, splice the Sec-WebSocket-Key and a fixed UUID "258eafa5-e914-4710995ca-c5ab0dc85b11", and then encrypt the spliced string with SHA1, after obtaining digest, perform a base64 encoding to obtain the Token.
In addition, it should be noted that the data structure sent back from the New and Old handshakes protoc
based on Websocet simple chat room (Nodejs + node-websocket-server)3 People collection This article, collection of this article published 24 days ago, there have been
135Times read a total
2A comment
3People to collect this article
Recently in the study of HTML5 related things, see WebSocket is a very powerful technology, so a small try, made a
Require_websocket,accept_websocketImport Dwebsocket@require_websocket #只接受websocket请求, do not accept HTTP requests, this is the adorner that called Dwebsocketdef websocket_test (Request):message = Request.websocket.wait ()Request.websocket.send (Message)@accept_websocket #既能接受http也能接受websocket请求def Echo (Request):If not Request.is_websocket ():Trymessage = Request. get[' message ']return HttpResponse (Mess
The example in this paper describes PHP based on WebSocket to build a simple chat room practice. Share to everyone for your reference. Specific as follows:
1. Preface
Company game inside there is a simple chat room, understand the later only know is Node+websocket do, think of PHP also to do a
.--------------------------------------------------------------------------------------The above is from the wiki, in general WebSocket realizes the two-way communication between the server and the browser, get rid of the previous one to answer the communication way, can freely transfer data.What are the advantages of websocket?
Because there is no HTTP header information, the transmitted packets a
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.