public void fileToPerson(chatSocket client, Byte[] buffer)
 {
     if (client.active)
     {
         int sent = 0;
         while (sent < buffer.Length)
             sent += client.socket.Send(buffer, sent, buffer.Length - sent, System.Net.Sockets.SocketFlags.None);
     }
 }
        public void run()
        {
            IPEndPoint ipep = new IPEndPoint(IPAddress.Any, setting.port);
            Socket newSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            newSocket.Bind(ipep);
            newSocket.Listen(10);

            IDcounter = 0;
            roomIDcounter = 0;

            lobby = new chatRoom(roomIDcounter++, "Lobby");
            roomList.Add(lobby);

            while (true)
            {
                Socket socket = newSocket.Accept();
                chatSocket client = new chatSocket(socket);

                try
                {
                    clientList.Add(client);
                    lobby.clientList.Add(client);
                    client.newListener(processMessage);
                    client.ID = IDcounter;
                    Console.WriteLine("New user with ID: " + IDcounter);
                    client.sendMessage("REGNEWUSER:" + IDcounter);
                    IDcounter++;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
 public void fileFromPerson(chatSocket client, Byte[] buffer)
 {
     int received = 0;
     while(received < buffer.Length)
         received += client.socket.Receive(buffer, received, buffer.Length - received, System.Net.Sockets.SocketFlags.None);
 }
Beispiel #4
0
        public void run()
        {
            IPEndPoint ipep = new IPEndPoint(IPAddress.Any, setting.port);
            Socket newSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            newSocket.Bind(ipep);
            newSocket.Listen(10);

            while (true)
            {
                Socket socket = newSocket.Accept();
                Console.WriteLine("-- WAITING FOR CONNECTIONS --\n");
                chatSocket client = new chatSocket(socket);

                try
                {
                    clientList.Add(client);
                    client.newListener(processMessage);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }