What does End Of File on a socket mean?

AaronLS picture AaronLS · Aug 24, 2009 · Viewed 21.8k times · Source

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.

Answer

Mark Rushakoff picture Mark Rushakoff · Aug 24, 2009

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.