Пример #1
0
        //
        // ======================= Connected state =======================
        //

        public Bytes Read()
        {
            if (tcpSession.CurrentState < TcpState.ESTABLISHED)
            {
                state = State.Closed;
                return(null); // connection closed
            }

            Bytes data = tcpSession.Read();

            if (data == null)
            {
                if (tcpSession.CurrentState != TcpState.ESTABLISHED)
                {
                    state = State.Closed;
                    return(null); // connection closed
                }
                else
                {
                    // Must be in the ROReadResult state. Here, there is
                    // no ConnectionClosed message.
                    state = State.Zombie;
                    return(null); // no more data -> Zombie
                }
            }
            else
            {
                if (tcpSession.AckNow == true)
                {
                    tcpSession.SendPacket(TcpFlags.ACK, false);
                }
                return(data);
            }
        }
Пример #2
0
        private static unsafe void HttpTest()
        {
            TCPConnection con = TCP.Bind(80);

            string message  = "<!doctype html><html><title>Van Sharpen</title><body>Wij serveren dit van Sharpen naar Dossche</body></html>";
            string httpResp = "HTTP/1.1 200 OK\r\nDate: Fri, 13 May 2005 05:51:12 GMT\r\nServer: Sharpen :)\r\nLast-Modified: Fri, 13 May 2005 05:25:02 GMT\r\nAccept-Ranges: bytes\r\nContent-Length: ";

            string count = message.Length.ToString();

            httpResp = String.Merge(httpResp, count);
            httpResp = String.Merge(httpResp, "\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n");

            string finalResp = String.Merge(httpResp, message);

            TCPPacketDescriptor *ptr;

            while (true)
            {
                ptr = TCP.Read(con);
                if (ptr == null)
                {
                    continue;
                }

                if (ptr->Type == TCPPacketDescriptorTypes.ACCEPT)
                {
                    Console.Write("New connection from: ");
                    for (int i = 0; i < 3; i++)
                    {
                        Console.WriteNum(ptr->Data[i]);
                        Console.Write('.');
                    }
                    Console.WriteNum(ptr->Data[3]);
                    Console.Write(" with XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.RECEIVE)
                {
                    Console.Write("New data from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");

                    TCP.Send(con, ptr->xid, (byte *)Util.ObjectToVoidPtr(finalResp), (uint)finalResp.Length);

                    TCP.Close(con, ptr->xid);
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.RESET)
                {
                    Console.Write("RESET from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.CLOSE)
                {
                    Console.Write("CLOSE from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else
                {
                    Console.WriteLine("Invalid ptr->Type!");
                    break;
                }

                Heap.Free(ptr);
            }

            Console.WriteLine("EXIAT");
            for (;;)
            {
                ;
            }

            TCP.Free(con);
        }