Exemplo n.º 1
0
        public void Run()
        {
            m_socket = new MicroSocket();

            //Console.Write("-");

            s_connectingSockets++;

            IPAddress baal = IPAddress.Parse("127.0.0.1");
            IPAddress torturer = IPAddress.Parse("192.168.1.1");

            if (m_socket.Connect(baal, 12345) == false)
            {
                Console.WriteLine("Connection failed");
                return;
            }

            s_connectingSockets--;
            s_connectedSockets++;

            /*
            while (s_connectedSockets < 500)
                MicroThread.CurrentThread.Sleep(1000);
            */

            //Console.Write(".");

            long sentBlocks = 0;

            byte[] buf = new byte[m_blockSize];
            while (true)
            {
                m_socket.Send(buf, buf.Length);

                sentBlocks++;
                s_totalBlocksSent++;

                if (sentBlocks >= m_blocksToSend)
                    break;
            }

            //Console.Write("x");
            s_connectedSockets--;

            m_socket.Shutdown();
            m_socket.Close();
        }
Exemplo n.º 2
0
        public MicroSocket Accept()
        {
            Print("Begin accepting");

            m_readCS.Enter();
            m_readingThread = MicroThread.CurrentThread;
            m_readingThread.Wait();
            m_readingThread = null;
            m_readCS.Exit();

            Print("Accept returned");

            Socket      newSocket = m_socket.Accept();
            MicroSocket s         = new MicroSocket(newSocket);

            return(s);
        }
Exemplo n.º 3
0
        public static void ListenRun()
        {
            MicroSocket listenSocket = new MicroSocket();

            IPEndPoint ep = new IPEndPoint(IPAddress.Any, 12345);
            listenSocket.Bind(ep);
            listenSocket.Listen(10);

            while (true)
            {
                MicroSocket socket = listenSocket.Accept();

                //Console.WriteLine("Accepted a new socket");
                //Console.Write(".");

                s_connectedSockets++;

                Server server = new Server(socket);
                MicroThread t = new MicroThread(server.SocketRun);
                t.Start();
            }
        }
Exemplo n.º 4
0
 public Server(MicroSocket s)
 {
     m_socket = s;
 }
Exemplo n.º 5
0
        public MicroSocket Accept()
        {
            Print("Begin accepting");

            m_readCS.Enter();
            m_readingThread = MicroThread.CurrentThread;
            m_readingThread.Wait();
            m_readingThread = null;
            m_readCS.Exit();

            Print("Accept returned");

            Socket newSocket = m_socket.Accept();
            MicroSocket s = new MicroSocket(newSocket);
            return s;
        }
Exemplo n.º 6
0
 internal static void RemoveSocket(MicroSocket s)
 {
     s_socketList.Remove(s);
     s_socketMap.Remove(s.Socket);
 }
Exemplo n.º 7
0
 internal static void AddSocket(MicroSocket s)
 {
     s_socketList.Add(s);
     s_socketMap[s.Socket] = s;
 }
Exemplo n.º 8
0
 internal static void AddSocket(MicroSocket s)
 {
     s_socketList.Add(s);
     s_socketMap[s.Socket] = s;
 }