套接字上的文件结束意味着什么?
在 Flex Builder 3 中使用 Action Script 3。
处理 SOCKET_DATA 事件时,我偶尔会看似随机地收到“错误 #2030:遇到文件结尾”。当调用socket.readInt()时。我很困惑这个错误意味着什么,因为我没有读取文件?我对套接字有点不熟悉。谢谢。
Using Action Script 3 in Flex Builder 3.
When handling a SOCKET_DATA event, I occasionally, seemingly at random, get an "Error #2030: End of file was encountered." when calling socket.readInt(). I'm confused as to what this error means, since I'm not reading a file? I'm a little unfamilier with sockets. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文件结束错误通常意味着套接字的另一端已关闭其连接,IIRC。
它是文件结尾的原因是,在程序中非常低的级别,磁盘上的文件和套接字都用数字表示 - 文件描述符——操作系统将其转换为表示文件、套接字、管道或其他任何内容的对象。
通常,您可以通过检查是否刚刚读入 EOF 来避免此类错误。如果您确实读取了 EOF,并且尝试再次从套接字/文件读取,那么您将收到 EOF 错误。
Update: According to the ActionScript 9.0 documentation, you do indeed get a close event if the other end closes the socket.
An end-of-file error typically means the other side of the socket has closed their connection, IIRC.
The reason it's end-of-file is that at a very low level within a program, a file on the disk and a socket are both represented with a number -- a file descriptor -- that the OS translates into the object representing a file or socket or pipe or whatever.
Usually, you can avoid this kind of error by checking if you just read in an EOF. If you did read an EOF, and you try reading from the socket/file again, then you will get an EOF error.
Update: According to the ActionScript 9.0 documentation, you do indeed get a close event if the other end closes the socket.
读取已关闭的套接字时,您将收到:
错误 #2002:在无效套接字上尝试操作。
如果读取的字节数超过可用字节数,则任何字节流上通常都会出现文件结束错误。文件、套接字等就是这种情况。对于闪存,它会在从
Socket
或ByteArray
读取时发生,甚至在其他情况下也可能发生。TCP/IP 是基于包的,但模拟流,因此您只能从流中读取已通过 TCP 包发送给您的数据。检查 Socket::bytesAvailable 来了解当前有多少字节可用。请始终记住,在一次操作中写入套接字的数据可能会到达多个数据包,每个数据包很可能会导致 Flash Player 触发
socketData
事件。When reading off a socket, that is closed, you will get:
Error #2002: Operation attempted on invalid socket.
End-of-file errors typically occur on any bytestreams, if you read more bytes than available. This is the case for files, sockets, etc. In the case of flash, it occurs when reading from a
Socket
or aByteArray
and maybe even in other cases.TCP/IP is package based, but emulates a stream, thus you can only read the data off the stream, that was already sent to you with TCP packages. Check
Socket::bytesAvailable
to find out, how many bytes are currently available. Always keep in mind, that the data you write to the socket in one operation, may arrive in multiple packages, each very probably causing flash player to triggersocketData
events.