简体   繁体   English

为什么我不能再发送到监听套接字了?

[英]Why can't I send to the listening socket anymore?

I'm writing a simple proxy (more a packet logger) for an online game in C#. 我正在使用C#为在线游戏编写一个简单的代理(更多的是数据包记录器)。 The basic Login process is like this: 基本的登录过程是这样的:

Client->Server: Login Packet - My proxy receives the packet, displays it and sends it to the server. 客户端->服务器:登录数据包-我的代理接收数据包,显示它并将其发送到服务器。

Server->Client: Connected! 服务器->客户端:已连接! Packet - My proxy again receives the packet, it also displays it again but when trying to send it to the client, it says: 数据包-我的代理再次收到该数据包,它也再次显示它,但是当尝试将其发送给客户端时,它说:

"A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied." “不允许发送或接收数据的请求,因为未连接套接字,并且(当使用sendto调用在数据报套接字上发送时)未提供地址。”

My code: http://lesderid.pastebin.com/NkEy7qQp 我的代码: http : //lesderid.pastebin.com/NkEy7qQp

171: listenSocket.Send(RecvBuffer2);

You shouldn't be trying to send on this listening socket. 您不应该尝试在此侦听套接字上发送。 You need to send on the socket that was created with EndAccept(). 您需要发送使用EndAccept()创建的套接字。 (winSock2 in your code - but you would need to scope it differently.) (代码中的winSock2-但您需要以不同的方式确定范围。)

Listening TCP sockets have but one function - accept client connections. 侦听TCP套接字只有一个功能-接受客户端连接。 The connection will occupy a new socket descriptor , ie a new socket will be created for each new client connection (and in C that's what accept(2) system call returns). 该连接将占用一个新的套接字描述符 ,即将为每个新的客户端连接创建一个新的套接字(在C中,这是accept(2)系统调用返回的内容)。

You cannot send(2) or recv(2) data on listening sockets. 您不能在侦听套接字上send(2)recv(2)数据。

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

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