Index: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.EHR/BMXNetEhrSessionConnection.cs
===================================================================
--- BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.EHR/BMXNetEhrSessionConnection.cs	(revision 1192)
+++ BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.EHR/BMXNetEhrSessionConnection.cs	(revision 1193)
@@ -20,4 +20,16 @@
             get { return 60000; }
             set { }
+        }
+
+        public override Encoding ConnectionEncoding
+        {
+            get
+            {
+                return System.Text.Encoding.Default;
+            }
+            set
+            {
+                ConnectionEncoding = value;
+            }
         }
 
Index: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/LoginProcess.cs
===================================================================
--- BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/LoginProcess.cs	(revision 1192)
+++ BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/LoginProcess.cs	(revision 1193)
@@ -282,4 +282,9 @@
         public bool AttemptUserInputLogin(string aDialogTitle, int maxAttempts, bool enableConnectionManagement,IWin32Window aUiOwnerForPositioningDialog)
         {
+            //test sam
+            //Framework.SocketBroker.Open(
+            //Framework.SocketBroker.PrimaryRemoteSession.TransmitRPC("XUS INTRO TEXT","","XUS SIGNON");
+            //test sam
+
             this.MaxAttempts = maxAttempts;
             RpmsLoginView view = (RpmsLoginView)new RpmsLoginDialog();
Index: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/WinFramework.cs
===================================================================
--- BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/WinFramework.cs	(revision 1192)
+++ BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/WinFramework.cs	(revision 1193)
@@ -657,4 +657,19 @@
         public LoginProcess CreateLoginProcess()
         {
+            /*
+            //sam test
+            BMXNetSocketConnectionSpec spec = new BMXNetSocketConnectionSpec();
+            spec.Server = this.ConnectionSettings.DefaultConnectionSpec.Server;
+            spec.Port = this.ConnectionSettings.DefaultConnectionSpec.Port;
+
+            var broker = new BMXNetSocketBroker();
+            broker.ConnectionSpec = spec;
+            var initcxn = new BMXNetSessionSocketConnection(broker);
+            initcxn.ConnectionSpec = spec;
+            initcxn.OpenConnectionCommon();
+            initcxn.IsConnected = true;
+            string txt = initcxn.TransmitRPC("XUS INTRO TEXT", "");
+            //end test
+            */
             return new LoginProcess(this);
 
Index: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Net/BMXNetSessionSocketConnection.cs
===================================================================
--- BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Net/BMXNetSessionSocketConnection.cs	(revision 1192)
+++ BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Net/BMXNetSessionSocketConnection.cs	(revision 1193)
@@ -10,4 +10,5 @@
 using System.Threading;
 using System.Timers;
+using System.Linq;
 
 namespace IndianHealthService.BMXNet.Net
@@ -115,5 +116,5 @@
      Port = "All",
      Transport = "All")]
-		protected virtual void OpenConnectionCommon()
+        protected virtual void OpenConnectionCommon()
 		{
 			try
@@ -346,9 +347,40 @@
 #endif
 
+            /******************INIT*****************/
             NetworkStream ns = tcpClient.GetStream();
             ns.ReadTimeout = this.ReceiveTimeout; //Timeout; throw exception automatically if we time out.
 
+            /*************SECURITY S-PACKET READ***********************/
+            int secPackLen = ns.ReadByte();  //Read S-Pack Length Byte
+            byte[] secPackContents = new byte[secPackLen];;
+            if (secPackLen > 0)
+            {
+                ns.Read(secPackContents, 0, secPackLen);
+            }
+
+            /****************ERROR S-PACKET READ******************/
+            int errPackLen = ns.ReadByte(); //Read S-Pack Length Byte
+            byte[] errPackConents = new byte[errPackLen];;
+            if (errPackLen > 0)
+            {
+                ns.Read(errPackConents, 0, errPackLen);
+            }
+
+            //If either one of these exists, then we have an error on the Mumps Database
+            if (secPackLen > 0 || errPackLen > 0)
+            {
+                //We still have to read the Data to empty the tcp OS buffers even if we have security/errors in the DB
+                while (ns.DataAvailable) ns.ReadByte() ;  //while loop to empty the buffer -- this is theoretically slow, but that's not important here
+
+                //Now decode them.
+                string secString = ConnectionEncoding.GetString(secPackContents);
+                string errString = ConnectionEncoding.GetString(errPackConents);
+                throw new BMXNetException("Mumps Database Security/Error: " + secString + " | " + errString);
+            }
+
+            /*****************DATA STREAM READ*******************/
+            //Data stream from VISTA ends when we find the EOT (ASCII 4) character
             MemoryStream mStream = new MemoryStream(1500); // Auto expanding memory storage for what we receive
-            int numberOfBytesRead = 0;  
+            int numberOfBytesRead = 0;
             bool bFinished = false;  // Have we found the End of Transmission (ASCII 4) yet?
 
@@ -362,33 +394,9 @@
                 else mStream.Write(bReadBuffer, 0, numberOfBytesRead - 1);           //otherwise, number of bytes minus the $C(4) at the end
             }
+
+            //At this point, we are done reading from the Network Stream. Now we have to decode the data.
             
-            //Read Security S-Packet
-            mStream.Seek(0, SeekOrigin.Begin);
-            int secLength = mStream.ReadByte();
-            byte[] secBytes = new byte[secLength];
-            if (secLength > 0)
-            {
-                mStream.Read(secBytes, 0, secLength);
-            }
-
-            //Read Error S-Packet
-            mStream.Seek(secLength + 1, SeekOrigin.Begin);
-            int errLength = mStream.ReadByte();
-            byte[] errBytes = new byte[errLength];
-            if (errLength > 0)
-            {
-                mStream.Read(errBytes, 0, errLength);
-            }
-
-            //If either one of these exists, then we have an error on the Mumps Database
-            if (secLength > 0 || errLength > 0)
-            {
-                string errString = ConnectionEncoding.GetString(secBytes);
-                string appString = ConnectionEncoding.GetString(errBytes);
-                throw new BMXNetException("Mumps Database Security/Error: " + errString + " | " + appString);
-            }
-
-            //No Errors. Decode the entire message starting from after the S packets above
-            string sReadBuffer = ConnectionEncoding.GetString(mStream.ToArray(), secLength + errLength + 2, mStream.ToArray().Length - (secLength + errLength + 2)); //decode
+            //Decode the entire message.
+            string sReadBuffer = ConnectionEncoding.GetString(mStream.ToArray()); //decode
 
             String decodedReceiveString = this.DecodeReceiveString(sReadBuffer);
@@ -636,9 +644,4 @@
                 this.SendString(this.Socket, ADEBLDMsg(m_cHDR, "BMXGetFac", aDuz));
                 return this.ReceiveString(this.Socket);
-#if DEBUG
-                _watch = new Stopwatch();
-                _watch.Start();
-#endif
-
 			}
 			catch (BMXNetException bmxEx)
