Skip to main content
September 22, 2008
Question

Weird socket bug, 'Error #2031: Socket Error'

  • September 22, 2008
  • 3 replies
  • 15894 views
I'm putting together an application which opens a connection to a server, sends a chunk of binary data and then closes the connection. When I run the application without handing IOEventError, I get the socket error message below but the data sends. When I handle IOEventError, I get the same message passed to the handler but no data is sent. When I capture TCP data during the connection, you can that without the handler a '[PSH, ACK]' packet of length 29 (my data) is sent out. With the handler, a '[FIN]' packet is sent instead. I've pasted the errors, code and TCP traffic below.

Has anyone else encountered this socket weirdness? How do I figure out what this error message means?

Thanks for the help!

-J. Flier

Error message to the console with no handler (but data sends): "Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
at handleSendPacketClick()[src\Test.mxml:156]
at Test_Button2_click()[\src\Test.mxml:333]"

Error message to the handler (no data sends): "IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 192.168.220.128" errorID=2031"

TCP traffic with no handler:
1 0.000000 192.168.220.1 192.168.220.128 TCP timelot > cbt [SYN] Seq=0 Win=65535 Len=0 MSS=1460
2 0.000484 192.168.220.128 192.168.220.1 TCP cbt > timelot [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460
3 0.000542 192.168.220.1 192.168.220.128 TCP timelot > cbt [ACK] Seq=1 Ack=1 Win=65535 Len=0
4 0.005418 192.168.220.1 192.168.220.128 TCP timelot > cbt [PSH, ACK] Seq=1 Ack=1 Win=65535 Len=29
5 0.005615 192.168.220.128 192.168.220.1 TCP cbt > timelot [ACK] Seq=1 Ack=30 Win=5840 Len=0
6 2.410136 192.168.220.1 192.168.220.128 TCP timelot > cbt [FIN, ACK] Seq=30 Ack=1 Win=65535 Len=0
7 2.450241 192.168.220.128 192.168.220.1 TCP cbt > timelot [ACK] Seq=1 Ack=31 Win=5840 Len=0
8 2.486507 192.168.220.128 192.168.220.1 TCP cbt > timelot [FIN, ACK] Seq=1 Ack=31 Win=5840 Len=0
9 2.486563 192.168.220.1 192.168.220.128 TCP timelot > cbt [ACK] Seq=31 Ack=2 Win=65535 Len=0

TCP traffic with handler:
17 438.448287 192.168.220.1 192.168.220.128 TCP dvt-data > cbt [SYN] Seq=0 Win=65535 Len=0 MSS=1460
18 438.448629 192.168.220.128 192.168.220.1 TCP cbt > dvt-data [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460
19 438.448683 192.168.220.1 192.168.220.128 TCP dvt-data > cbt [ACK] Seq=1 Ack=1 Win=65535 Len=0
20 438.449489 192.168.220.1 192.168.220.128 TCP dvt-data > cbt [FIN, ACK] Seq=1 Ack=1 Win=65535 Len=0
21 438.451503 192.168.220.128 192.168.220.1 TCP cbt > dvt-data [ACK] Seq=1 Ack=2 Win=5840 Len=0
22 438.452759 192.168.220.128 192.168.220.1 TCP cbt > dvt-data [FIN, ACK] Seq=1 Ack=2 Win=5840 Len=0
23 438.452793 192.168.220.1 192.168.220.128 TCP dvt-data > cbt [ACK] Seq=2 Ack=2 Win=65535 Len=0

var socket:Socket=new Socket();

// First we generate our packet
msg=generateMessage();

// Then we open a connection
//socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
socket.connect(backendIPTextInput.text, int(textInput.text));

// Finally we send the packet
socket.writeBytes(msg);
socket.flush();
socket.close();
    This topic has been closed for replies.

    3 replies

    Participant
    April 22, 2010

    Having spent three days trying to run this down, I'm going to start by saying that I'm honestly surprised no ones put together a page that says, "Oh hey, before you use XML sockets here's 150 things you need to know first."  Or maybe someone did put that page together but I couldn't find it.  So in the interest of saving someone the big hassle I just had, here's what you might be doing wrong.

    Start here:

    http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary860.html

    Then have a look at this, particularly the example:

    http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/XMLSocket.html

    Now you might be tempted to skip all of the adding of those event listeners, but if you do if any kind of communication problem arises in the connection Flash won't know how to handle it and you'll get Error #2031 or #2044 or both.

    But wait, that's not all!  You also have to come up with some way to let the PLAYER (not your application, not the sever) know that it's allowed to communicate on the port, and for that you need this document:

    http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

    Seriously, if this helps you, please let me and Adobe know.

    Participating Frequently
    July 5, 2009

    I feel your pain... these kinds of errors are most typically associated with Flash security and often result in reverse engineering some of the 'secret sauce' behind socket handling. To say that Flash is picky about ports, policy, and timing is an understatement. There is a great article by Nuno Freitas that you should take a look at.

    http://www.broculos.net/tutorials/how_to_make_a_multi_client_flash_java_server/20080320/en

    Cheers,

    Rick Winscot

    Participant
    January 3, 2009
    I am getting the same error mesage. If you got any solution then please share it with me ..

    Thanks In Advance
    Prashant Tambe