Exemple #1
0
        private static void ReadFile(karlient sender)
        {
            int r   = 0;
            int tot = 0;

            byte[] buffer = new byte[8192];

            string fullname = sender.input.ReadString();
            string file     = Path.GetFileName(fullname);
            long   size     = sender.input.ReadInt64();

            using (FileStream fileStream = new FileStream(file, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                while ((r = sender.input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    fileStream.Write(buffer, 0, r);
                    tot += r;

                    if (tot == size)
                    {
                        break;
                    }
                }
            }
            Console.WriteLine("[+] Successfully received a file: {0}, Size: {1}KB", file, (decimal)size / 1024m);
        }
Exemple #2
0
        private static void client_packetReceived(karlient sender, int value)
        {
            switch (value)
            {
            case 0x58:
                ReadMessage(sender);
                break;

            case 0x48:
                ReadFile(sender);
                break;
            }
        }
Exemple #3
0
        protected static void disKonnectCallBack(IAsyncResult ar)
        {
            karlient konteks = (karlient)ar.AsyncState;

            try
            {
                konteks.xSocket.EndDisconnect(ar);
            }
            catch (SocketException e)
            {
                // lmao
            }
            konteks.OnStateChanged(false, "[-] Successfully disconnected from server");
        }
Exemple #4
0
        private static void server_cC(karver sender, karlient client)
        {
            Console.WriteLine("[+] Client Successfully connected!!");

            client.packetReceived += client_packetReceived;
            client.stateChanged   += client_stateChanged;

            client.Start();

            lock (clientz)
            {
                clientz.Add(client);
            }
        }
Exemple #5
0
        private static void client_stateChanged(karlient client, bool connected, string reason)
        {
            Console.Write("[+] Connected: {0}, Reason: {1}", connected, reason);

            if (!connected)
            {
                lock (clientz)
                {
                    if (clientz.Contains(client))
                    {
                        clientz.Remove(client);
                    }
                }
            }
        }
Exemple #6
0
        protected static void acceptCallBack(IAsyncResult ar)
        {
            karver konteks = (karver)ar.AsyncState;

            try
            {
                Socket   koneksi = konteks.socket.EndAccept(ar);
                karlient client  = new karlient(koneksi);

                konteks.OnKlientKonnected(client);
            }
            catch (SocketException e)
            {
            }
            konteks.socket.BeginAccept(new AsyncCallback(acceptCallBack), konteks);
        }
Exemple #7
0
        protected static void konnectCallBack(IAsyncResult ar)
        {
            karlient konteks = (karlient)ar.AsyncState;

            try
            {
                konteks.xSocket.EndConnect(ar);
                if (konteks.xSocket.Connected)
                {
                    konteks.OnStateChanged(true, "[+] Client Successfully connected to server");
                }
            }
            catch (SocketException e)
            {
                konteks.OnStateChanged(false, "[-] Client failed to connect to server.../");
            }
        }
Exemple #8
0
 protected void OnKlientKonnected(karlient client)
 {
     cC?.Invoke(this, client);
 }
Exemple #9
0
        private static void ReadMessage(karlient sender)
        {
            string message = sender.input.ReadString();

            Console.WriteLine(message);
        }