public Packet readPacket(TcpClient tcp)
        {
            Stream stream = tcp.GetStream();
            /*if(!headerRead)
            {
                byte[] header = new byte[3];
                stream.Read(header, 0, 3);
                if(equals(header, Packet.HEADER)){
                    Console.WriteLine("Header is equal!");
                }
                headerRead = true;
            }*/

            Packet packet = new Packet();
            byte[] bytes = new byte[1045];
            stream.Read(bytes, 0, bytes.Length);
            MemoryStream mstr = new MemoryStream(bytes);
            mstr.Position = 0;
            packet.Read(mstr);
            Console.WriteLine("Packet " + packet.callId);

            //if (packet.callId == 0)
            //{
                //Console.WriteLine("Prev");
                //print(prev, prevB);
                //Console.WriteLine("Current");
                print(packet, bytes);

             //           }

            this.prev = packet;
            this.prevB = bytes;
            return packet;
        }
Exemplo n.º 2
0
        public void DoPut()
        {
            for (int c=0; ; c++)
            {
                Thread.Sleep(1000);
                Console.WriteLine("OPERATION " + c);
                Packet request = new Packet();
                Random random = new Random(5);

                byte[] key = new byte[10];
                byte[] val = new byte[1000];
                random.NextBytes(key);
                request.set("c:default", ClusterOperation.CONCURRENT_MAP_PUT, key, val);
                Call call = new Call(request);
                outThread.enQueue(call);
                Packet result = null;
                int timeout = 5000;
                for (int i = 1; ; i++)
                {
                    result = call.getResult(timeout);
                    if (result != null)
                    {
                        if (result.callId != request.callId)
                        {
                            Console.WriteLine("Id's don't match!");
                        }
                        Interlocked.Increment(ref puts);
                        break;
                    }
                    else {
                        Console.WriteLine("Call"  + call.getId() + " didn't get answer within "+ timeout*i/1000 + " seconds");
                    }
                }
            }
        }
 public void write(TcpClient tcpClient, Packet packet)
 {
     Stream stream = tcpClient.GetStream();
         if (!headersWritten) {
             stream.Write(Packet.HEADER, 0, Packet.HEADER.Length);
             headersWritten = true;
             Console.WriteLine("Header is sent");
         }
         send(tcpClient, packet);
 }
        public void print(Packet packet, byte[] bytes)
        {
            Console.WriteLine("");
            Console.WriteLine("Packet: " + packet.callId);

            foreach (byte b in bytes)
            {
                Console.Write(b);
                Console.Write(".");
            }
            if (packet.callId == 0)
                Thread.Sleep(100000);
        }
Exemplo n.º 5
0
 public void setResult(Packet response)
 {
     //this.inQ.Enqueue (response);
     inbQ.Add(response);
 }
Exemplo n.º 6
0
 public Call(Packet request)
 {
     this.id = incrementCallId();
     this.request = request;
     this.request.callId = id;
 }
 public static void send(TcpClient tcpClient, Packet packet)
 {
     Stream stream = tcpClient.GetStream();
     packet.write (stream);
 }