Flash套接字已连接,但未发送数据
本文关键字:数据 套接字 连接 Flash | 更新日期: 2023-09-27 18:29:32
我正在使用Client/Server应用程序,我的客户端是Flash,服务器是C#。
我连接到服务器并发送第一个数据,到目前为止没有问题,但当我发送第二个数据时,它不会发送任何数据,也没有任何操作。我能做些什么来解决这个问题?
服务器:
private void OnDataReceived(IAsyncResult asyn)
{
OyuncuSoketi socketData = (OyuncuSoketi)asyn.AsyncState;
int iRx = 0;
// Complete the BeginReceive() asynchronous call by EndReceive() method
// which will return the number of characters written to the stream
// by the client
iRx = socketData.m_currentSocket.EndReceive(asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0);
String data = new String(chars);
if (data.IndexOf("policy-file-request") != -1)
{
LST_LOG.Items.Add(" Flash Player Policy File İstendi");
LST_LOG.Items.Add(" Policy File Gönderiliyor");
try
{
Policyfilegonder(socketData.m_currentSocket);
LST_LOG.Items.Add(" Policy File Gönderildi");
LST_LOG.Items.Add("Oyuncu Baglandi " + DateTime.Now.ToString());
}
catch
{
LST_LOG.Items.Add(" !!!Policy File Gönderilemedi!!!");
LST_LOG.Items.Add(" !!!Oyuncu Baglantisi basarisiz!!! " + DateTime.Now.ToString());
}
}
else
{
string[] gelen_bilgi;
data.Replace("'0", "");
gelen_bilgi = data.Split('_');
switch (gelen_bilgi[0])
{
case "'0": LST_LOG.Items.Add("Oyuncu Baglantısı koptu" + DateTime.Now.ToString());
break;
case "OYUNAGIRIS": socketData.Id = Convert.ToInt32(gelen_bilgi[1]); SocketList.Add(socketData); LST_LOG.Items.Add("Oyuna Giris"); socketData.m_currentSocket.Send(System.Text.Encoding.Default.GetBytes("Kabul'0"));
break;
case "ODAYAGIRIS": socketData.Oda = Convert.ToInt32(gelen_bilgi[1]);
LST_LOG.Items.Add("Oyuncu " + Convert.ToInt32(gelen_bilgi[1]) + " Nolu Odaya Girdi");
break;
case "ODADANCIKIS": LST_LOG.Items.Add("Oyuncu " + Convert.ToInt32(socketData.Oda) + " Nolu Odadan Çıktı");
socketData.Oda = -1;
break;
case "SALONAGIRIS": MessageBox.Show("Salona Girildi");
//socketData.Salon = Convert.ToInt32(gelen_bilgi[1]);
// LST_LOG.Items.Add("Oyuncu " + Convert.ToInt32(gelen_bilgi[1]) + " Nolu Salona Girdi");
break;
case "SALONDANCIKIS": LST_LOG.Items.Add("Oyuncu " + Convert.ToInt32(socketData.Salon) + " Nolu Salondan Çıktı");
socketData.Salon = -1;
break;
default:
break;
}
}
}
private void WaitForData(Socket soc)
{
if (pfnWorkerCallBack == null)
{
// Specify the call back function which is to be
// invoked when there is any write activity by the
// connected client
pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
}
OyuncuSoketi packet = new OyuncuSoketi();
packet.m_currentSocket = soc;
// Start receiving any data written by the connected client
// asynchronously
soc.BeginReceive(packet.dataBuffer, 0, packet.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, packet);
}
客户:
private function onConnect(e:Event){
if(fl_socket.connected){
durum_bilgisi.text = "Sunucuya Baglanildi " + e;
fl_socket.writeMultiByte("OYUNAGIRIS_"+FBuid.toString()+"_"+String.fromCharCode(0),"UTF8");
//This data is sending to server by the client
fl_socket.flush();
}else{
durum_bilgisi.text = "Baglantida Hata olustu " + e ;
}
}
//
private function salonaGir(e:ListEvent):void{
var o:Object = e.item;
girilenSalon = o.No;
girilenSalon--;
fl_socket.writeMultiByte("SALONAGIRIS_"+girilenSalon.toString()+"_"+FBuid.toString()+"_"+String.fromCharCode(0),"UTF8"); // but this data is not sent :(
fl_socket.flush();
gotoAndStop(2);
OdalariGetir();
}//salonaGir Sonu
套接字连接仍处于连接状态,未断开连接,但未向服务器发送数据
NetworkStream ns = clientTCP.GetStream();
StreamWriter sw = new StreamWriter(ns);
sw.WriteLine("<cross-domain-policy><allow-access-from domain='"*'" to-ports='"*'"/></cross-domain-policy>'0");
sw.Close();