问题标签 [tcpserver]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
20942 浏览

python - socket.error: [Errno 111] 连接被拒绝

我正在尝试准备原型,但无法建立连接。我在客户端和服务器上都使用 OpenSSL。

和客户:

最后,错误:

任何帮助,将不胜感激。我觉得我错过了一些简单的东西,但我是网络编程的新手。

netstat -tpn服务器运行时的输出:

0 投票
0 回答
603 浏览

java - 调试停止后如何清除悬空的ServerSocket,而不重新启动matlab?

我有一些类似下面的代码,使用 matlab 中的 java 套接字。我不认为解决方案需要特定于 matlab ......

问题:如果我在 socket 可以被 server_socket.close 关闭之前点击 debug-quit,它会保持悬空/打开状态。唯一可行的解​​决方法是停止并重新启动 matlab,我猜这会杀死后台套接字。如果此函数保持打开状态,我如何更一般地关闭 ServerSocket?

我试过用谷歌搜索,但不太确定要使用什么关键字,并且关于 java 套接字存在信息过载......

编辑:一个解决方案是使它成为一个脚本而不是一个函数(即删除第一行和最后一个'end')。这样,在调试终止后 server_socket 仍然存在。但我想更好地了解处理套接字的位置,并且不希望所有其他变量都必须持续存在。

0 投票
1 回答
7580 浏览

python - Python TPCServer rfile.read 块

我正在编写一个简单的SocketServer.TCPServer请求处理程序 ( StreamRequestHandler),它将捕获请求以及标头和消息正文。这是为了伪造一个我们可以用于测试的 HTTP 服务器。

我可以毫不费力地抓住请求行或标题。

如果我试图从现有的东西中获取更多rfile,代码块。如何在不知道其大小的情况下获取所有请求正文?换句话说,我没有Content-Size标题。

这是我现在拥有的一个片段:

0 投票
1 回答
2086 浏览

python - Python JSON-RPC_2.0 TCP Server Client Explained

I'm having a difficult time fully understanding the nature of a TCP server/client relationship when a JSON string is sent to the server. The information I need may be out there, but I'm perhpas not using the correct search paramaters as I'm looking.

I've built a Python TCP, JSON-RPC Server from the following examples:

In both cases, I can communicate with the Python server from a Python console on a different computer, sending commands from one (the client) to the other (server). In all of the examples, I've had to install the libraries mentioned above on both the client and the server machines in order to facilitate the TCP communication.

So the background to my situation and question is, when does JSON enter the mix? This is what I want to do:

Setup a Python TCP server that accepts a JSON string from a remote client inside (or outside) the network. The server parses the JSON string, fetches the method and parameters from the objectified string, and executes the method. The server then sends a JSON string result to the calling client. In this case, the client is a mobile application (iPad, Android, etc) with a JavaScript library that I'll use to send the requests to the server.

Why would I need a Python client? From what I can gather, the client just needs to open a connection to the server and then send the JSON string, right? Why do all the code samples include Python client examples? Are they assuming a server machine is going to talk to a server machine, so they have included client code to help generate the JSON string that will be sent to the server?

If I assume that a Python client isn't really needed for anything, I've been sending JSON strings to the Python server from the iPad, but in each case the server is reporting a "Bad request syntax" error. I'll pen a new question on that issue if I'm understanding the current question correctly.

Insight is appreciated.

0 投票
1 回答
1745 浏览

python - Python TCP 服务器 JSON 错误请求语法

我在 Python-2.7 中创建的 TCP JSON-RPC 服务器有一个奇怪的问题。我使用以下代码构建服务器:

我正在从同一本地网络中将客户端与服务器通信。在控制台窗口中,我可以从 Python 中连接到服务器并针对服务器运行命令。一切都很好。

但是,当我尝试从移动应用程序(在本例中为 iPad)发送 JSON 字符串时,服务器上出现错误。我还下载了此工具以尝试发送 JSON 字符串:http ://www.simplecomtools.com/productcart/pc/downloads/tcptesttool.zip但具有相同的错误结果。服务器正在报告“错误的请求语法”错误。我尝试了几个不同的字符串 - 显示的错误是:

192.168.1.107 - - [13/Oct/2012 09:48:17] 代码 400,消息错误请求语法(“{'jsonrpc':'2.0','method':'add','params':[3, 6],'id':'8'}") 192.168.1.107 - - [13/Oct/2012 09:48:17] "{'jsonrpc':'2.0','method':'add','params ':[3,6],'id':'8'}" 400 -

192.168.1.107 - - [13/Oct/2012 09:49:44] 代码 400,消息错误请求语法 ('{"jsonrpc":"2.0","method":"add","params":[3, 6],"id":"8"}') 192.168.1.107 - - [13/Oct/2012 09:49:44] "{"jsonrpc":"2.0","method":"add","params ":[3,6],"id":"8"}" 400 -

192.168.1.107 - - [13/Oct/2012 09:50:49] 代码 400,消息错误请求语法 ('{"jsonrpc":"2.0","method":"add","params":{"x ":3,"y":6},"id":"8"}') 192.168.1.107 - - [13/Oct/2012 09:50:49] "{"jsonrpc":"2.0","method ":"add","params":{"x":3,"y":6},"id":"8"}" 400 -

192.168.1.107 - - [13/Oct/2012 17:11:59] 代码 400,消息错误请求语法(“{'jsonrpc':'2.0','method':'add','params':{'x ':3,'y':6}, 'id':8}") 192.168.1.107 - - [13/Oct/2012 17:11:59] "{'jsonrpc':'2.0', '方法': 'add', 'params':{'x':3,'y':6}, 'id':8}" 400 -

我真的不知道为什么服务器会认为请求语法不好,即使问这个问题我也觉得有点傻。关于我可以尝试解决语法错误的任何想法?

0 投票
1 回答
25893 浏览

c++ - C++ 套接字编程 TCP/IP 套接字缓冲区的最大大小?

我正在使用 C++ TCP/IP 套接字。根据我的要求,我的客户端必须连接到服务器并读取它发送的消息(这真的很新,不是吗)但是......在我的应用程序中我必须等待一段时间(通常为 1 - 2 小时) 在我真正开始阅读消息(通过 recv() 或 read())之前,服务器仍然继续发送消息。

我想知道缓冲区的容量是否有限制,以防这些消息未被读取,以及谁的物理内存用于缓冲这些消息?发件人还是收件人?

0 投票
1 回答
2062 浏览

c# - 通过在 TCPClient 中使用 StreamReader.ReadLine() 从 TCPServer 缓冲区读取消息(数据)(ReadLine() 直到断开连接才会返回)

创建 TCPServer 的 hercules 程序 我的表格

我的方法有问题。我StreamReader.ReadLine()写了一个 C# 程序,但只有 TCPclient 端。我正在使用 Hercules 程序来创建 TCPServer。我输入了端口号并建立了连接。然后我运行我的程序并单击连接按钮。然后,我与 TCPServer 建立了联系。

我将数据从 TCPClient 发送到 Hercules(TCPServer) 没有问题。如图所示,我将字符串输入到“Entered to Send”EditText,然后单击Send按钮并发送字符串。(我们可以从Received data部分观察发送数据。)

到这里为止,我没有问题。发送部分后,我无法将数据从 hercules(TCPServer) 发送到 TCPClient。为了发送数据,我将数据写入 发送部分并单击Send按钮。之后,要查看即将到来的数据,您应该单击Show按钮.....问题就在这里。我无法从ReadStream Buffer中读取数据。我调试了我的程序,发现有问题的部分是:

在该try部分内线;

有问题 .ReadLine() 没有从缓冲区读取数据。这是有趣的部分,当您发送数据并单击Show按钮时,程序会冻结,但如果您hercules.png通过单击Close按钮关闭连接,read_stream.ReadLine();则会获取数据并放入Received: EditText。

  • 为什么在与 TCPServer 断开连接后需要数据?
  • 可能是\r\n 字符有问题?
  • 我以为它在等待下一个角色。所以,当我断开连接时它起作用了,因为它意识到三个不再是字符。我的问题是:

如何使用read_stream.ReadLine(); 采取不断开连接发送数据?

这是我的 main.cs 我忘了添加它。您可以编写它并尝试我的项目...注意:这是可移植的 hercules 的链接,您可以轻松运行它 [ http://www.hw-group.com/products/hercules/index_en.html] 3

0 投票
2 回答
274 浏览

c# - 来自 MSDN 杂志的关于 TCP 异步服务器的问题

MSDN 杂志 2005 年 8 月的这篇文章中,Daryn Kiely 解释了构建 TCP 服务器的三种方法。

第三种模型,异步模型,是最适合我需要的模型,但我对其内部工作的一些细节有一些了解。

问题 1 - 关于接受连接的线程数

在示例中,当通过调用启动服务器时Start(),代码会创建十个接受连接的线程池:

我不明白为什么你不能只使用一个_serverSocket.BeginAccept,为什么数字十。

问题 2 – 大约收到零字节

ReceiveCallback()中,如果我们收到零字节,我们将关闭连接。为什么?当接收到零字节时总是认为客户端关闭了连接?在我在这里进行的测试中,当我的客户端关闭连接时,我得到一个在 SocketException 中捕获的异常。我在这里错过了什么吗?

问题 3 – 关于重新开始接收的需要

在套接字中接收到某些内容后,它会被放回 BeginReceive。为什么我们需要重新开始接收?这不应该是自动的吗?

问题 4 – 关于缓冲区大小

使用 255 字节的缓冲区。我知道如果一条消息的长度大于缓冲区大小,它会在多个接收中分散。我应该设置一个足够大的缓冲区大小以保证没有消息会被碎片化,还是我必须提供代码来处理消息碎片(在一个缓冲区中加入多个接收)?

0 投票
1 回答
5783 浏览

ruby - 如何使用 read、readpartial 和 read_nonblock 从 ruby​​ 中的 TCPServer 套接字读取

我有一个关于从套接字读取以及如何在 Unicorn 或 Mongrel 等 Ruby 服务器上进行管理的两部分问题

  1. 我了解到,从套接字读取与读取文件不同,并且没有发送明显的 EOF 消息,并且数据是无穷无尽的流。那么你怎么知道什么时候停止阅读呢?例如,在这种情况下,当我通过浏览器访问我的服务器时,我的 TCPServerhttp://localhost:9799会在没有更多数据要读取后挂起,并且也不会抛出 EOFError。

我想知道 Ruby 服务器使用的最佳实践/标准方法是什么。我看到 Unicorn 使用来自kgio库的 read_nonblock 而 mongrel 使用 readpartial (我不确定这些,但通过代码,我觉得这是采用的方法。)即使检查 \r\n 服务器如何知道输入完成。可以解释应该如何做到这一点(我认为gets这不是方法 - 它带有read, readpartial, read_nonblock)。

2)。我真的很感激关于如何在独角兽或乘客等服务器中实现这一点的几行

谢谢你。

0 投票
1 回答
290 浏览

android - 将android模拟器作为服务器运行

我想从 android 模拟器接收 AT 命令并从用 C 编写的 TCP 客户端程序发回回复。

我通过给出命令“ emulator -shell-serial tcp::4444,server”在 ubuntu-10.4 系统上作为服务器运行 Android ICS 模拟器,在另一个终端中我正在运行用 C 编写的 TCP 客户端,试图连接到同一个端口。

我能够看到模拟器 GUI 出现,但我没有在客户端收到任何 AT 命令。