|
|||
|
Can anyone post a short socket example that connects to the local host (127.0.0.1) on port 5001? I tried the following FFish script, but I get error 10038 (Socket operation on non-socket) when I try to connect.
-------------------------------------------------------------------------- var rval = false; var address = "127.0.0.1"; var port = 5001; var sock = new Socket; rval = sock.connect(address, port); if (rval == false) { Dialogs.msgBox("Error connecting socket: " + sock.error, "Error", 16); return; } -------------------------------------------------------------------------- Any and all help is appreciated. Thanks, Terry |
|
|||
|
|
|
|||
|
You should create the socket first
![]() ------------------------------------------------------------------------ -- var rval = false; var address = "127.0.0.1"; var port = 5001; var sock = new Socket; sock.create(); rval = sock.connect(address, port); if (rval == false) { Dialogs.msgBox("Error connecting socket: " + sock.error, "Error", 16); return; } ------------------------------------------------------------------------ -- |
|
|||
|
Ok. Here's how the code looks now:
------------------------------------------------------------------------- var ret = 0; var s = new Socket; var conn = true; s.create(); conn = s.connect("127.0.0.1", 5001); if (conn == false) { Dialogs.msgBox("Error connecting socket: " + s.error, "Error", 16); return; } var instream = new StringStream; var outstream = new StringStream; instream.write("This is a test"); s.send(instream, instream.length); ret = s.receive(outstream, 1024); if (ret == -1) { Dialogs.msgBox("Error during receive: " + s.error, "Error", 16); return; } ------------------------------------------------------------------------- Whats weird about this is that "conn" winds up being false even when the socket successfully connects, but the error is different. What's even weirder is that you can safely ignore the error 10035 and remove the "if (conn == false)" statement in the code above and everything still works fine. The problem with that is you won't catch "real" errors. At this point, the s.send() works fine, then I get an error (10057 : the socket is not connected) when I try to receive. This seems strange because I know the server is sending a reply, so I have no idea why the socket is being reported as closed. Any ideas? Thanks, Terry |
|
|||
|
Sorry, it's really a bug of SWFKit. Sometimes the error propety cannot catch the real error.
The connect or send method should always return a WSAEWOULDBLOCK(10035) error because they are asynchronous operations. When the operations are done, the onConnect, onSend or onReceive events will be fired. |
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|