客户端flash:
[code]
package
{
import flash.net.Socket;
import flash.events.*;
import flash.display.Sprite;
import flash.errors.*;
import flash.display.SimpleButton;
import flash.utils.Timer;

public class Client extends Sprite
{
private var mysocket:Socket;
private var host:String="127.0.0.1";
private var port:int=2046;

private var timer:Timer=new Timer(1000);
public function Client()
{
btn.addEventListener(MouseEvent.CLICK,SendData);
mysocket=new Socket();

mysocket.addEventListener(Event.CONNECT,OnConnect);
mysocket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
mysocket.addEventListener(ProgressEvent.SOCKET_DATA , receivedata);
//mysocket.addEventListener(SecurityError
mysocket.connect(host,port);

timer.addEventListener(TimerEvent.TIMER,showTimer);
timer.start();
}
private function OnConnect(e:Event):void
{
log("连接成功");
mysocket.writeUTFBytes("test");
mysocket.flush();//发送数据
}
private function ioErrorHandler(e:IOErrorEvent):void
{
log("连接失败");
}
private function receivedata(e:ProgressEvent):void
{
log("收到的字节数"+mysocket.bytesAvailable);
var msg:String="";
while (mysocket.bytesAvailable)
{
msg+=mysocket.readMultiByte(mysocket.bytesAvailable,"utf8");
log(msg);
}
}
private function SendData(e:MouseEvent):void
{
mysocket.connect(host,port);
log("发送");
mysocket.writeUTFBytes("i am flash/n");
mysocket.flush();//发送数据
}

private function showTimer(e:TimerEvent):void
{
mysocket.connect(host,port);
log("发送2");
mysocket.writeUTFBytes("my time/n");
mysocket.flush();//发送数据
}

private function log(s:String):void
{
ta.appendText(s+"\n");
ta.verticalScrollPosition=ta.maxVerticalScrollPosition;
//ta.scrollV=ta.maxScrollV;

}

private function clearHandler():void{
socket.removeEventListener(ProgressEvent.SOCKET_DATA, receivedata);
socket.removeEventListener(Event.CONNECT, OnConnect);
//socket.removeEventListener(Event.CLOSE, closeHandler);
socket.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
}
}

[/code]
服务器端php:
[code]

[/code]