首页 >php教程 >php手册 >php模拟飞鸽传输协议,代码实现向飞鸽发送消息

php模拟飞鸽传输协议,代码实现向飞鸽发送消息

WBOY
WBOY原创
2016-06-13 09:34:53830浏览

飞鸽传书协议:
1:23149:riverlet:127.0.0.1:\x20:balabalabalabala
版本号:包编号:发送者姓名:发送者主机名:命令字:附加信息(消息内容)

<?<span>php

</span><span>define</span>("IPMSG_SENDMSG", 0x00000020);   <span>//</span><span> 0x00000020 命令字代表不同的命令</span><span>
#</span><span>define("IPMSG_SECRETOPT", 0x00000200);// 0x00000200 另一个命令字</span>
<span>define</span>("IPMSG_DEFAULTPORT", 2425);     <span>//</span><span>2425飞鸽传书端口</span>

<span>$sender</span> = 'XXX'<span>;
</span><span>$from</span> = '127.0.0.1'<span>;
</span><span>$msg_content</span> = 'XXXXXXXXXXXXXXXXXX'<span>;
</span><span>$send_to</span> = '192.168.10.110';  <span>//</span><span>对方主机IP</span>

<span>$fs</span> = <span>fsockopen</span>("udp://".<span>$send_to</span>, IPMSG_DEFAULTPORT); <span>//</span><span>用户数据报协议,一种无连接的传输层协议</span>
<span>fwrite</span>(<span>$fs</span>, "1:".<span>time</span>().":".<span>$sender</span>.":".<span>$from</span>.":".(IPMSG_SENDMSG).":".<span>$msg_content</span><span>);
</span><span>fclose</span>(<span>$fs</span>);

 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn