Example #1
0
    //connects the client to the server
    public bool Connect()
    {
        //ESTABLISH CONNECTION THEN MAKE THREAD TO READ BYTES FROM STREAM
        try
        {
            client = new TcpClient(SERVER_LOCATION, SERVER_PORT);
            nws    = client.GetStream();
            ThreadSock tsock = new ThreadSock(nws, this);
            t = new Thread(new ThreadStart(tsock.Service));
            t.IsBackground = true;
            t.Start();
            threadState  = true;
            sw           = new StreamWriter(nws);
            sw.AutoFlush = true;
        }

        catch (Exception ex)
        {
            Console.WriteLine(ex.Message + " : OnConnect");
        }

        if (client == null)
        {
            return(false);
        }
        return(client.Connected);
    }
Example #2
0
        public void SendMoreThanMTUDroppedOnReceiveByThreadSock()
        {
            var bufferPool = new ByteBufferPool();
            var sock       = new ThreadSock(bufferPool, AddressFamily.InterNetwork, new LoggerStub());

            sock.Listen(23460);

            UdpClient udpClient = new UdpClient();

            udpClient.Connect(IPAddress.Loopback, 23460);
            udpClient.Send(new byte[BareSock.MTU + 1], BareSock.MTU + 1);

            var receivedPacket = Utils.WaitOnReceive(sock);

            Assert.IsNull(receivedPacket.Buffer);
            Assert.AreEqual(0, receivedPacket.Offset);
            Assert.AreEqual(0, receivedPacket.Length);

            sock.Close();
        }
Example #3
0
    public bool Connect()
    {
        //********* COMPLETE THE FOLLOWING CODE
        //********* ESTABLISH CONNECTION THEN MAKE THREAD TO READ BYTES FROM STREAM
        try
        {
            client = new TcpClient();
            client.Connect(SERVER_LOCATION, SERVER_PORT);
            nws = client.GetStream();
            ThreadSock ts = new ThreadSock(nws, this);
            t = new Thread(new ThreadStart(ts.Service));
            t.IsBackground = true;
            t.Start();
        }
        catch ( Exception ex )
        {
            print ( ex.Message + " : OnConnect port " + SERVER_PORT);
        }

        if ( client == null ) return false;
        else
        return connected = client.Connected;
    }
Example #4
0
    //connects the client to the server
    public bool Connect()
    {
        //ESTABLISH CONNECTION THEN MAKE THREAD TO READ BYTES FROM STREAM
        try
        {
            client = new TcpClient(SERVER_LOCATION, SERVER_PORT);
            nws = client.GetStream();
            ThreadSock tsock = new ThreadSock(nws, this);
            t = new Thread (new ThreadStart(tsock.Service));
            t.IsBackground = true;
            t.Start();
            threadState = true;
            sw = new StreamWriter(nws);
            sw.AutoFlush = true;
        }

        catch ( Exception ex )
        {
            Console.WriteLine ( ex.Message + " : OnConnect");
        }

        if ( client == null ) return false;
        return client.Connected;
    }
Example #5
0
 public void Setup()
 {
     _bufferPool = new MockBufferPool();
     _sock       = new ThreadSock(_bufferPool, AddressFamily.InterNetwork, new LoggerStub());
 }