简体   繁体   English

如何使用 PHP 将字符串发送到特定端口?

[英]How can I send a string to a specific port using PHP?

I have to send a string from an HTML page to a specific ip and port address using PHP.我必须使用 PHP 将字符串从 HTML 页面发送到特定的 ip 和端口地址。

Example: clicking on a button(on my HTML site) should result in sending the string "hello" to port 7474 of ip xxxx .示例:单击按钮(在我的 HTML 站点上)应该会导致将字符串"hello"发送到 ip xxxx的端口7474

How can i do that with PHP?我怎样才能用 PHP 做到这一点?

Use fsockopen to open a connection to the port and get a filehandle, then use fwrite to write to that filehandle.使用fsockopen打开到端口的连接并获取文件句柄,然后使用fwrite写入该文件句柄。

You'll usually want to close the connection with fclose when you're done.完成后,您通常会希望使用fclose关闭连接。 PHP will close the connection for you at the end of the script if you forget.如果您忘记了,PHP 将在脚本末尾为您关闭连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM