2015-04-27 205 views
1

使用netcat,我需要创建一个简单的服务器来响应简单的JSON数据。拒绝Netcat服务器连接

首先我有一个HTML页面尝试:

while true ; do nc -l 8888 < index.html ; done 

,甚至更简单:

netcat -l 8888 < index.html 

然后在我的浏览器我这样做:

http://localhost:8888/index.html 

我也尝试使用netcat进行连接:

nc -vz 127.0.0.1 8888 

每个收益率的 '连接被拒绝' 的结果:

本地主机[127.0.0.1] 8888(DDI-TCP-1):连接被拒绝

如何解决这个错误?

+0

哪个os? BSD和GNU/Linux的netcats有很大的不同 – stringy05

回答

1

问题已解决。

我不得不使用

netcat -l -p 8888 < index.html 

这样我可以听将localPort。现在我正在工作。

+0

'-p'确实帮助我了!你能把它标记为接受的答案吗? – n611x007

0

尝试没有index.html的浏览器

$ netcat -l 8888 < index.html 

在浏览器中使用http://localhost:8888

如果这不起作用,尝试远程

$ telnet localhost 8888 
Trying 127.0.0.1... 
Connected to localhost. 
Escape character is '^]'. 
test 
Connection closed by foreign host. 

我的index.html只包含字符串'test'。如果无法建立连接,则问题是网络问题。

+0

嗨。那是我尝试过的。它不起作用。这是一件简单的事,不知道为什么它不起作用......无论如何感谢 – JohnMurhy

+0

你在浏览器中忽略了index.html,它不起作用?它适用于我的机器。这可能是你的环境,防火墙,网络设置... – NaN

+0

是的,我已经试过它没有index.html。那么问题是什么? – JohnMurhy