コード例 #1
0
        static void Recieve(object obj)
        {
            Socket clientSoc = (Socket)obj;

            while (true)
            {
                byte[] buffer = new byte[clientSoc.ReceiveBufferSize];

                int amoutOfBytes = clientSoc.Receive(buffer);

                object test = buffer.Deserialize();

                if (test.ToString() == "1")
                {
                    Console.WriteLine("Client " + clientSoc.RemoteEndPoint + " Refreshed");
                }
                else
                {
                    Person newPer = new Person();
                    newPer = (Person)buffer.Deserialize();

                    MyDBHandler.Insert(newPer);


                    perlst = MyDBHandler.GetData();

                    foreach (Socket item in socLst)
                    {
                        item.Send(perlst.Serialize());
                    }
                }
            }
        }
コード例 #2
0
        public static void Accept(object obj)
        {
            Socket serverSoc = (Socket)obj;

            while (true)
            {
                Socket clientSoc = serverSoc.Accept();
                Console.WriteLine("Client Connected");

                Thread recieve = new Thread(new ParameterizedThreadStart(Recieve));
                recieve.Start(clientSoc);
                socLst.Add(clientSoc);

                perlst = MyDBHandler.GetData();

                foreach (Socket item in socLst)
                {
                    item.Send(perlst.Serialize());
                }
            }
        }