Are you using asynchronous read and
write? I couldn’t get my “blocking” setup to work
reasonably.
Tracy
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Andre Ehlert
Sent: Monday, December 05, 2005
8:29 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] XMLSocket
Hi all,
in
most cases my SocketServer-class is sending and receiving messages without any
problems.
But
espacially if the Socket is receiving messages (onXML) and has to send outgoing
messages "at the same time" this will fail from time to time...
Does
anybody have an idea?
a++
André
###############
The
class:
###############
import
mx.events.EventDispatcher;
import
mx.utils.Delegate;
[Event("connectionSucceeded")]
[Event("connectionFailed")]
[Event("connectionClosed")]
[Event("messageReceived")]
[Event("debugMessage")]
class
SocketServer
{
public var addEventListener:Function;
public var removeEventListener:Function;
private var dispatchEvent:Function;
private var _socket:XMLSocket = null;
private var _server:String;
private var _port:Number;
public function SocketServer()
{
_socket = new XMLSocket();
EventDispatcher.initialize(this);
_socket. OnConnect);
_socket. OnClose);
_socket. OnXML);
}
public function connectToServer(IPAddress:String,
Port:Number) :Void
{
_server = IPAddress;
_port = Port;
_socket.connect(_server,
_port);
}
public function close() :Void
{
_socket.close();
}
private function OnConnect(success :Boolean) :Void
{
if (success)
dispatchEvent({type: "connectionSucceeded"});
else
dispatchEvent({type:
"connectionFailed"});
}
private function OnXML(message :XML) :Void
{
dispatchEvent({type:
"messageReceived", message: message});
dispatchEvent({type:"debugMessage", message:message,
direction:"receive"});
}
public function send(message:String):Void
{
dispatchEvent({type:"debugMessage", message:message,
direction:"send"});
_socket.send(message);
}
private function OnClose() :Void
{
dispatchEvent({type:
"connectionClosed"});
}
}
################
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
YAHOO! GROUPS LINKS
|
- RE: [flexcoders] XMLSocket Tracy Spratt
-