Home > Backend Development > PHP Tutorial > PHP怎么向某个IP的某个端口发送一个字节

PHP怎么向某个IP的某个端口发送一个字节

WBOY
Release: 2016-06-13 13:32:13
Original
1559 people have browsed it

PHP如何向某个IP的某个端口发送一个字节?
如题,比如向202.117.120.241的2012端口发送一个字节,字节的8位分别是00100000,该怎样实现?

------解决方案--------------------
$fp = fsoctopen('202.117.120.241', 2012);
fwrite($fp, chr(bindec('00100000')));
------解决方案--------------------
fsocketopen();
------解决方案--------------------
晕啊。。
fsockopen();
------解决方案--------------------

PHP code
$fp = fsockopen('202.117.120.241', 2012, $ercode, $ermsg);
if($ercode !== 0)
    exit ('error:'. $ermsg);
$st = sprintf("%b", 00100000);
fread($fp, $st);
<br><font color="#e78608">------解决方案--------------------</font><br>这是可能由于202.117.120.241这个机子没有监听2012端口。这不是代码的问题造成的。<br>另外我写的<br>$st = sprintf("%b", 00100000); 是错误的。我对二进制字节的理解有误,1楼是正确的 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template