Ejemplo n.º 1
0
        public void ProcessData(SocketAsyncEventArgs args)
        {
            // Get the last message received from the client, which has been stored in the stringbuilder.
            String received = stringbuilder.ToString();

            //TODO Use message received to perform a specific operation.


            string content2 = new String((char)hl7.MLLP_FIRST_END_CHARACTER, 1);
            content2 = content2 + new String((char)hl7.MLLP_LAST_END_CHARACTER, 1);



            // get the message up to the eof characters
            // and remove the message from the string builder
            if (received.IndexOf(content2) > -1)
            {
                if (received.IndexOf(content2) == 0)
                {

                    totalbytecount = 0;
                    stringbuilder.Length = 0;
                    Console.WriteLine("HERE CLEARING THINGS OUT");
                }
                else
                {

                    //int temp = received.IndexOf(content2);
                    int temp2 = received.IndexOf(content2);
                    totalbytecount = totalbytecount - received.Length;
                    received = received.Substring(1, temp2);  //Might need + 2 here to get the full message

                    stringbuilder.Remove(0, temp2);
                    totalbytecount = 0;
                    stringbuilder.Length = 0;
                    Console.WriteLine("Received: \"{0}\". The server has read {1} bytes. {2}", received, received.Length, temp2);

                    Message m = new Message(received);

                    AckMessage ack = new AckMessage(received);

                    Console.WriteLine(ack.ack);

                    Byte[] sendBuffer = Encoding.ASCII.GetBytes(ack.ack);
                    args.SetBuffer(sendBuffer, 0, sendBuffer.Length);
                    this.OwnerSocket.Send(args.Buffer);

                }

            }
Ejemplo n.º 2
0
        public void ProcessClientData(SocketAsyncEventArgs args)
        {
            // Get the last message received from the client, which has been stored in the stringbuilder.
            String received = stringbuilder.ToString();

            //TODO Use message received to perform a specific operation.

            string content2 = new String((char)hl7.MLLP_FIRST_END_CHARACTER, 1);
            content2 = content2 + new String((char)hl7.MLLP_LAST_END_CHARACTER, 1);

            // get the message up to the eof characters
            // and remove the message from the string builder
            if (received.IndexOf(content2) > -1)
            {
                if (received.IndexOf(content2) == 0)
                {

                    totalbytecount = 0;
                    stringbuilder.Length = 0;
                    Console.WriteLine("HERE CLEARING THINGS OUT");
                }
                else
                {

                    //int temp = received.IndexOf(content2);
                    int temp2 = received.IndexOf(content2);
                    totalbytecount = totalbytecount - received.Length;
                    received = received.Substring(1, temp2);  //Might need + 2 here to get the full message

                    stringbuilder.Remove(0, temp2);
                    totalbytecount = 0;
                    stringbuilder.Length = 0;
                    Console.WriteLine("Received: \"{0}\". The server has read {1} bytes. {2}", received, received.Length, temp2);

                    Message m = new Message(received);

                    AckMessage ack = new AckMessage(received);

                    Console.WriteLine(ack.ack);

                    Byte[] sendBuffer = Encoding.ASCII.GetBytes(ack.ack);
                    args.SetBuffer(sendBuffer, 0, sendBuffer.Length);
                    this.OwnerSocket.Send(args.Buffer);

                }

            }

            // All the data has been read from the
            // client. Display it on the console.
            //Console.WriteLine("Read {0} bytes from socket. \n Data : {1}",
            //    content.Length, content);
            // Echo the ACk message here async or in the caller
            //Send(handler, content);

            //TODO: Load up a send buffer to send an ack back to the calling client

            //

            // Clear StringBuffer, so it can receive more data from the client.
        }