Esempio n. 1
0
 public void StartClient(string url, int port)
 {
     this.serverURL            = url;
     this.port                 = port;
     this.tcpClient            = new TcpClient(serverURL, port);
     this.connected            = true;
     this.dataBeingTransferred = new GNIPendingData(false);
 }
Esempio n. 2
0
File: Structs.cs Progetto: VDZx/GNI
 public GNIClientInformation(uint clientID, System.Net.Sockets.TcpClient tcpClient)
 {
     this.clientID = clientID;
     this.tcpClient = tcpClient;
     this.name = "Anonymous";
     this.data = new GNIDataSet(true);
     this.dataBeingTransferred = new GNIPendingData(false);
 }
Esempio n. 3
0
 public void StartClient(string url, int port)
 {
     this.serverURL = url;
     this.port = port;
     this.tcpClient = new TcpClient(serverURL, port);
     this.connected = true;
     this.dataBeingTransferred = new GNIPendingData(false);
 }
Esempio n. 4
0
        public override void Update()
        {
            if (connected)
            {
                //Check if connection still exists
                if (tcpClient == null)
                {
                    connected = false; OnConnectionLost();
                }
                //And is still connected
                if (!tcpClient.Connected)
                {
                    connected = false; OnConnectionLost();
                }

                //If it's not currently loading any data...
                if (dataBeingTransferred.started == false)
                {
                    //Start loading if data length is available
                    if (tcpClient.Available > 3)
                    {
                        byte[] buffer = new byte[4];
                        tcpClient.GetStream().Read(buffer, 0, 4);
                        int dataLength = BitConverter.ToInt32(buffer, 0);
                        dataBeingTransferred = new GNIPendingData(dataLength);
                    }
                }

                //Now, if it's already started loading data...
                if (dataBeingTransferred.started)
                {
                    int bytesToRead = tcpClient.Available;
                    if (bytesToRead > 0)
                    {
                        if (bytesToRead > dataBeingTransferred.datalength - dataBeingTransferred.dataread)
                        {
                            bytesToRead = dataBeingTransferred.datalength - dataBeingTransferred.dataread;
                        }
                        byte[] buffer = new byte[bytesToRead];
                        tcpClient.GetStream().Read(buffer, 0, bytesToRead);
                        dataBeingTransferred.AddData(buffer);

                        if (dataBeingTransferred.datalength == dataBeingTransferred.dataread)
                        {
                            HandleSignal(dataBeingTransferred.data);
                            dataBeingTransferred = new GNIPendingData(false);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public override void Update()
        {
            if (connected)
            {
                //Check if connection still exists
                if (tcpClient == null) { connected = false; OnConnectionLost(); }
                //And is still connected
                if (!tcpClient.Connected) { connected = false; OnConnectionLost(); }

                //If it's not currently loading any data...
                if (dataBeingTransferred.started == false)
                {
                    //Start loading if data length is available
                    if (tcpClient.Available > 3)
                    {
                        byte[] buffer = new byte[4];
                        tcpClient.GetStream().Read(buffer, 0, 4);
                        int dataLength = BitConverter.ToInt32(buffer, 0);
                        dataBeingTransferred = new GNIPendingData(dataLength);
                    }
                }

                //Now, if it's already started loading data...
                if (dataBeingTransferred.started)
                {
                    int bytesToRead = tcpClient.Available;
                    if (bytesToRead > 0)
                    {
                        if (bytesToRead > dataBeingTransferred.datalength - dataBeingTransferred.dataread)
                            bytesToRead = dataBeingTransferred.datalength - dataBeingTransferred.dataread;
                        byte[] buffer = new byte[bytesToRead];
                        tcpClient.GetStream().Read(buffer, 0, bytesToRead);
                        dataBeingTransferred.AddData(buffer);

                        if (dataBeingTransferred.datalength == dataBeingTransferred.dataread)
                        {
                            HandleSignal(dataBeingTransferred.data);
                            dataBeingTransferred = new GNIPendingData(false);
                        }
                    }
                }
            }
        }