public bool OnReceiveData(Connection connection)
        {
            Data dato = DataProccessor.GetInstance().LoadObject(connection.StreamReader);

            return(CommandHandler.GetInstance().Handle(connection, dato));
            // return true;
        }
Пример #2
0
        /// <summary> Called when a message is extracted from the socket </summary>
        /// <param name="pSocket"> The SocketClient object the message came from </param>
        /// <param name="iNumberOfBytes"> The number of bytes in the RawBuffer inside the SocketClient </param>
        static public void MessageHandlerServer(SocketBase socket, int iNumberOfBytes)
        {
            try
            {
                SocketClient pSocket = ((SocketClient)socket);
                // Find a complete message
                String strMessage = System.Text.ASCIIEncoding.ASCII.GetString(pSocket.RawBuffer, 0, iNumberOfBytes);

                Console.WriteLine("Message=<{0}>", strMessage);
                DataProccessor.ManageData(pSocket, strMessage);
            }
            catch (Exception pException)
            {
                Console.WriteLine(pException.Message);
            }
        }
Пример #3
0
        private void ReceiveData()
        {
            while (notEnd)
            {
                try
                {
                    Data dato = DataProccessor.GetInstance().LoadObject(br);
                    CommandHandler.GetInstance().Handle(this, dato);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    Console.WriteLine(e.Message);
                    notEnd = false;
                    CloseConn();
                }
            }

            Console.WriteLine("termino");
        }
Пример #4
0
 public static void CloseHandler(SocketBase socket)
 {
     Console.WriteLine("Close Handler");
     Console.WriteLine("IpAddress: " + socket.IpAddress);
     DataProccessor.clientsDict.Remove(DataProccessor.GetClientId((SocketClient)socket));
 }
Пример #5
0
        private void UploadFile()
        {
            Data reqUploadResponse = new Data();

            try
            {
                reqUploadResponse = DataProccessor.GetInstance().LoadObject(uploadStreamReader);
            }
            catch (Exception)
            {
                Cancel = true;
            }

            if (!Cancel && reqUploadResponse.Payload.Message.Equals(MessageConstants.MESSAGE_SERVER_READY))
            {
                FileInfo   fileInfo   = new FileInfo(FileSelected.FullName);
                FileStream fileStream = fileInfo.OpenRead();

                const int BUFF_SIZE = 1024;
                byte[]    buffer    = new byte[BUFF_SIZE];

                long bytesCount = 0;

                try
                {
                    while (!done && !Cancel)
                    {
                        int countRead = fileStream.Read(buffer, 0, BUFF_SIZE);
                        bytesCount += countRead;
                        if (countRead > 0)
                        {
                            if (countRead < BUFF_SIZE)
                            {
                                percentageUploaded = 100;
                                done = true;
                            }
                            uploadNetStream.Write(buffer, 0, countRead);
                            uploadNetStream.Flush();
                        }
                        else
                        {
                            //no leyo nada de la entrada (cantidad de bytes justa, en la siguiente lectura)
                            done = true;
                        }
                        if (!Cancel)
                        {
                            if (bytesCount == FileSelected.Size && FileSelected.Size == 0)
                            {
                                percentageUploaded = 100;
                                done = true;
                            }
                            else
                            {
                                percentageUploaded = (int)(bytesCount * 100 / FileSelected.Size);
                            }
                        }
                        NotifyProgress(done ? "Subida completa !" : "Subiendo ...");
                    }
                }
                catch (Exception)
                {
                    FatalError();
                }
                fileStream.Close();
            }
            else
            {
                FatalError("El servidor no esta disponible para descargas.");
            }
        }