Use php for socket programming in linux and report a connection rejection error. Please check it out.

Source: Internet
Author: User
In linux, php is used for socket programming and a connection rejection error is reported. Please check that this post was last edited by lovegis0101 at 08:40:57.

I am new to Linux, php, and socket (haha ....), I found some information on the Internet and wrote two basic php scripts on the client and server. in Windows, the test can communicate with each other. Then, the client script is placed in Linux, but the following error is reported:
PHP Warning: socket_connect (): unable to connect [111]: Connection refused in/socketClient. php on line 12, 12 is to call the socket_connect method, the error here
The system environment is like this. I have installed a Linux virtual machine on a Windows host. the Windows system ip address is 192.168.0.2 and the Linux system ip address is 192.168.102. the Two System networks are connected through bridging, linux can connect to the network through Windows.
This problem has plagued me for several days. I have not found a solution for searching online. please help me to see it.
Attach the script code:
Server:
 

Client:
 


Reply to discussion (solution)

It's so fast. let's take a look. I'm in a hurry. this step cannot be implemented, so we can't proceed next.

Since Windows is acceptable, linux is not acceptable. check the environment problems first...

Okay, the problem is found. The ip address monitored by the server should not be 127.0.0.1, but the actual ip address, 192.168.0.2.
The error code 111 is reported because there is no server program or the server program is not started.

It is good to find the problem by yourself.

Since Windows is acceptable, linux is not acceptable. check the environment problems first...


Haha thanks for reminding me that I have encountered this problem today and solved it.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.