2
我正在使用客戶端/服務器應用程序,我的客戶端是Flash,服務器是C#。已連接Flash Socket但未發送數據
我連接到服務器併發送第一個數據,目前沒有問題,但是當我發送第二個數據時,它不發送任何數據,沒有任何操作。我能做些什麼來解決這個問題?
服務器:
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
套接字連接仍然連接,它沒有斷開,但它不是在插座上發送和數據服務器
代碼樣本服務器? – Odys 2012-03-29 21:40:26
@odyodyodys我添加了我的代碼。 – 2012-03-30 08:27:48
您是否找到了解決方案?如果你在這裏發佈它會很有幫助。 – EnKrypt 2012-05-16 11:19:09