简体   繁体   中英

Flash Socket connected, but not sending data

I am working an Client/Server application my client is Flash, and server is C#.

I am connected to server and send first data and no problems so far, but when i sending the second data, its not send any data, there is no action. What can I do to solve this problem?

Server :

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);

    }

Client:

        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

socket connection is still connected, its not disconnected but its not send and data to server

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM