Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

直接使用simpleclient.c编译运行时总是出现拒绝连接,是为什么呢 #38

Open
pengtangtang opened this issue Dec 6, 2019 · 9 comments

Comments

@pengtangtang
Copy link

No description provided.

@acxmx
Copy link

acxmx commented Apr 28, 2020

同问,望懂的同学帮助下!

@kele1997
Copy link

因为 httpd 监听的端口号是 4000,simple_client.c发送的端口号是9734,需要对应下端口号。但是呢,改完端口号,也没啥反应,会阻塞。我正在看代码

@kele1997
Copy link

kele1997 commented Apr 28, 2020

  1. simplecilent.c 不是一个 http 客户端,只是一个发送 'A' 的套接字程序
  2. 测试 httpd ,可以使用 curl -v localhost:4000/index.html
  3. 如果运行 curl 异常(阻塞,无结果,结果不对),那么你可能运行的是无线程版的,需要把 accpet_request 函数中的第一行修改一下,从 int client = (intptr_t)arg; 修改为 int client = *(int*)arg;

@acxmx
Copy link

acxmx commented Apr 28, 2020

  1. simplecilent.c 不是一个 http 客户端,只是一个发送 'A' 的套接字程序
  2. 测试 httpd ,可以使用 curl -v localhost:4000/index.html
  3. 如果运行 curl 异常(阻塞,无结果,结果不对),那么你可能运行的是无线程版的,需要把 main 函数中的 accept_request(&client_sock); 修改为accept_request(client_sock);

谢谢大神的解答,很棒啊!
不过,client_socket最终还是会在accept_request函数内被强转成一个整型,也就是说要使用的是socket 的文件描述符,而不是它的地址,这样看来,是源码写错了吧? 也就是accept_request(&client_sock);多了一个取地址符?

@TronYY
Copy link

TronYY commented Jun 19, 2020

改好后在浏览器输入例如localhost:4000 浏览器没有反应

@kele1997
Copy link

@TronYY https://gist.github.com/kele1997/8d2db488b9fc1e5830fc7e1f6e29dfbd#file-httpd-c-L55
直接用这个文件,或者自己注意修改 void accept_request(int arg) 第55行左右的 arg 参数,和 509行传参

@TronYY
Copy link

TronYY commented Jun 19, 2020

其实是权限的问题 要进入到index所在的目录后 终端输入sudo chmod 600 index.html

@liuxianyi
Copy link

其实是权限的问题 要进入到index所在的目录后 终端输入sudo chmod 600 index.html

为什么需要为用户设置权限600呢,我设置777就不能访问html页面,非常疑惑?

@Liusandian
Copy link

Liusandian commented Nov 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants