Blogger Information
Blog 3
fans 0
comment 0
visits 3935
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
用workerman做个命令行聊天室
愤怒的青草
Original
1456 people have browsed it

在网上看到有workerman这个PHP框架,于是心血来潮去做一个聊天室,完成我在PHP路上第一个像样的作品。

workerman主页:workerman

此聊天室想做得跨平台并且还要有web网页端,所以做成多个接口socket/websocket(我不会告诉你我才知道他们俩不在同一层上)供客户端调用。

首先想到命令行下可以用telnet当做客户端,所以我就先来做个telnet接口。

在telnet发来命令$data做命令判断时,发现总是不能匹配if($data=="echo"){}总是失败,后来用var_dump($data)一看不是echo应有的string(4)而是string(6)。我判断是telnet掺杂了其他字符,于是

bin2hex($data)=6563686f0d0a

发现多出俩个奇怪字符,

    $data=str_replace(chr(0x0d),"",$data);
    $data=str_replace(chr(0x0a),"",$data);

果断去除掉。

此处做了个小研究ASCII回车与换行


下面设计一下聊天的数据结构吧

$house
 [0]-room0public
  [0]-name
  [1]-passwd
  [2]-room hoster
  [3]-userlist
   [0]-room hoster
   [1]-userA_UID
   [*]-...
  [4]-banlist
   [0]-userA_UID
  [5]-chat messages
   [0]-list title describe
   [1]-msg1
    [0]-message sender
    [1]-send time
    [2]-msg content
    [*]-other
   [*]-msg*
  [*]-...
 [*]-room*private

$private_msg
 [0]-Sender_UID
 [1]-Receiver_UID
 [2]-time
 [3]-msg



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post