-1

I have a server, listening for connections from a SWF file in browser.

When running on local, it picks up a connection then drops it very soon after leaving in the log:

[31/1/2016 18:10:14] 127.0.0.1connected. Full 127.0.0.1:58482

[31/1/2016 18:10:14] Got < policy-file-request/> from client 0

[31/1/2016 18:10:16] Client0 disconnected and removed.

This is not logged when the server is ran and the client is launched in debug mode in flashdevelop, but the client connects and acts as desired.

I am including my TcpClient class, have i made a mistake or typo or should this be behaving differently when ran in browser and not in flashdevelop?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace ParticleFramework.Communication
{
    class TcpClient
    {
        #region Required Variables
        public Socket socket;
        public int index;
        private byte[] dataBuffer = new byte[0x400];
        private AsyncCallback ReceiveCallback;
        private AsyncCallback SendCallback;
        #endregion

        #region ArchiCruise Vars
        public ArchiCruise.Users.UserObject userObject;
        public string ip;
        #endregion

        public TcpClient(Socket sock, int num)
        {
            index = num;
            socket = sock;

            ip = socket.RemoteEndPoint.ToString().Split(new char[] { ':' })[0];

            ReceiveCallback = new AsyncCallback(this.ReceivedData);
            SendCallback = new AsyncCallback(this.sentData);

            this.WaitForData();
        }

        public void Disconnect()
        {
            if (socket.Connected)
            {
                socket.Close();
                if (userObject != null) userObject.remove();
                Particle.Server.removeClient(this);
                Log.Info("Client" + this.index + " disconnected and removed.");
                Console.WriteLine("Client" + this.index + " disconnected.");
            }
        }

        private void ReceivedData(IAsyncResult iAr)
        {
            try
            {
                int count = 0;

                try
                {
                    count = socket.EndReceive(iAr);
                }
                catch
                {
                    Disconnect();
                }

                StringBuilder builder = new StringBuilder();
                builder.Append(System.Text.Encoding.Default.GetString(this.dataBuffer, 0, count));
                string str = System.Text.Encoding.Default.GetString(this.dataBuffer, 0, count);

                if (str.Contains("<policy-file-requet/>"))
                {
                    Log.Info("Sending policy file to client" + this.index);
                    rawSend("<?xml version\"1.0\"?><cross-domain-policy><allow-access-from-domain=\"*\" to-ports=\"*\" /><cross-domain-policy>" + Convert.ToChar(0));
                }
                else if (!(str.ToString() == ""))
                {
                    string packet = str.Substring(0, str.Length - 1);
                    //packet = ArchiCruise.Security.Encryption.decrypt(packet);
                    Log.Info("Got " + str + " from client " + this.index);

                    Particle.packetClass.handle(packet, this);
                }
                else
                {
                    Disconnect();
                }
            }
            catch (Exception exception)
            {
                Log.Info("Data recieve error: " + exception.ToString() + " " + exception.Source);
                Disconnect();
            }
            finally
            {
                this.WaitForData();
            }
        }

        private void WaitForData()
        {
            try
            {
                socket.BeginReceive(this.dataBuffer, 0, this.dataBuffer.Length, SocketFlags.None, this.ReceiveCallback, socket);
            }
            catch
            {
                Disconnect();
            }
        }

        public void sendData(string Data)
        {
            Data += (char)1;
            rawSend(Data);
        }

        internal void rawSend(string Data)
        {
            try
            {
                Data += "\0";
                byte[] bytes = System.Text.Encoding.Default.GetBytes(Data);

                socket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(this.sentData), null);
                Log.Info("Sent " + Data + " to client " + this.index);
            }
            catch
            {
                Disconnect();
            }
        }

        private void sentData(IAsyncResult iAr)
        {
            try
            {
                socket.EndSend(iAr);
            }
            catch
            {
                Disconnect();
            }
        }
    }
}
Community
  • 1
  • 1
Sauced Apples
  • 1,163
  • 2
  • 14
  • 37

1 Answers1

3

You've made a spelling mistake.

if (str.Contains("<policy-file-requet/>"))

Should be

if (str.Contains("<policy-file-request/>"))
DominicEU
  • 3,585
  • 2
  • 21
  • 32
  • Crap, thanks. That does not fully solve the issue as I now just get; `[31/1/2016 18:19:50] Particle Server logging started... [31/1/2016 18:19:51] Test query succeeded. Database initialized. [31/1/2016 18:20:04] 127.0.0.1connected. Full 127.0.0.1:58625 [31/1/2016 18:20:04] Sending policy file to client0 [31/1/2016 18:20:04] Sent < ?xml version"1.0"?>< cross-domain-policy>< allow-access-from-domain="*" to-ports="*" />< cross-domain-policy> to client 0 [31/1/2016 18:20:04] Client0 disconnected and removed.` – Sauced Apples Jan 31 '16 at 18:20
  • It needs to obviously continue onwards and connect the client to the server and get their ssoticket etc... but its still kicking them off the server – Sauced Apples Jan 31 '16 at 18:22
  • Get their SSO Ticket? :) Sorry, this is not a service to aid emulation development. – DominicEU Jan 31 '16 at 18:23
  • No, i know. But the question was to find out why the server is prematurely kicking the user off, while you found a mistake it didn't fix that but thank you anyway – Sauced Apples Jan 31 '16 at 18:24