フラッシュ ビルダー 4 でソケットを使用すると問題が発生します。以下のコードは、受信側の c# sockerServer に一連のバイトを送信します。フラッシュ ビルダーで発生したエラーを手動で無視すると、バイトは正常に送信され、すべてが 127.0.0.1:10 で正常に送信されます。Flexにエラーが表示されることなく、同じ結果を得ることができれば。
だから、私は2つの質問があります:
1) ソケットを閉じようとするとエラーが返されるのはなぜですか? コンテキストについては、以下の closeConnection() を参照してください。直前にフラッシュしようとしましたが、役に立ちませんでした。
2) socket.flush() を使用すると何も送信されないのはなぜですか?
package
{
import flash.events.IOErrorEvent;
import flash.net.Socket;
import flash.utils.ByteArray;
public class socketClient
{
private var socket:Socket;
public function openConnection(address:String, port:int):void
{
if (socket != null && socket.connected)
socket.close();
socket = new Socket();
try {
socket.connect( address, port );
}
catch( e:Error ) { }
}
public function sendProtocol(p:socketProtocol):void {
//p.serialize() gets me a bunch of bytes in a ByteArray
var buffer:ByteArray = p.serialize();
socket.writeBytes(buffer, 0, buffer.length);
//Nothing happens when I flush
socket.flush();
}
public function closeConnection():void {
//As soon as I get to socket.close(), I get this
//"Unhandled IOErrorEvent:. text=Error #2031: Socket Error."
socket.close();
}
}
}
私はこのようなクラスを使用します:
var socket:socketClient = new socketClient();
//works fine, I see the connection on the server
socket.openConnection("127.0.0.1", 10);
//no errors, but nothing sent
socket.sendProtocol(protocol);
//returns the error. (if manually dismissed, data is sent)
socket.closeConnection();