Changeset 1180 for BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Net
- Timestamp:
- May 11, 2011, 9:17:45 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Net/BMXNetSessionSocketConnection.cs
r1146 r1180 24 24 public static int DefaultReceiveTimeout = 40000; 25 25 26 26 27 private int _sendTimeout = 0; 27 28 … … 63 64 } 64 65 66 public override Encoding ConnectionEncoding // Default Encoding determined by Windows; typically a Windows Code Page 67 { 68 get; 69 set; 70 } 71 72 65 73 public BMXNetSessionSocketConnection(BMXNetBroker aBroker):base(aBroker) 66 74 { … … 70 78 m_sWISH = ""; 71 79 m_cHDR = ADEBHDR(m_sWKID,m_sWINH,m_sPRCH,m_sWISH); 80 81 ConnectionEncoding = Encoding.Default; 72 82 73 83 } … … 218 228 } 219 229 220 221 222 223 230 bool m_bLogging = false; 224 231 … … 239 246 { 240 247 String cMSG = ADEBLDMsg(m_cHDR, "BMX CONNECT STATUS", ""); 241 248 #if DEBUG 249 _watch = new Stopwatch(); 250 _watch.Start(); 251 #endif 242 252 this.SendString(this.Socket, cMSG); 243 253 String strReceive = ReceiveString(this.Socket); 254 #if DEBUG 255 _watch.Stop(); 256 257 Debug.WriteLine("Time: " + _watch.ElapsedMilliseconds + " ms"); 258 Debug.WriteLine("---"); 259 _watch = null; 260 #endif 261 244 262 String port = BMXNetBroker.Piece(strReceive, "|", 1); 245 263 String message = BMXNetBroker.Piece(strReceive, "|", 2); … … 275 293 } 276 294 277 295 Stopwatch _watch = new Stopwatch(); 296 278 297 protected override String SendReceiveString(string cSendString, string cMult) 279 298 { 280 299 #if DEBUG 281 Stopwatch_watch = new Stopwatch();300 _watch = new Stopwatch(); 282 301 _watch.Start(); 283 Debug.WriteLine("Sending (T:" + Thread.CurrentThread.ManagedThreadId + "): " + cSendString);284 302 #endif 285 303 this.SendString(this.m_pCommSocket, cSendString, cMult); 304 Debug.WriteLine("Time After Send: " + _watch.ElapsedMilliseconds + " ms"); 286 305 string _received = this.ReceiveString(this.m_pCommSocket); 287 306 #if DEBUG 288 Debug.WriteLine("Received(T:" + Thread.CurrentThread.ManagedThreadId + "): " + _received.Replace((char) 30, (char) 10)); 307 _watch.Stop(); 308 289 309 Debug.WriteLine("Time: " + _watch.ElapsedMilliseconds + " ms"); 290 310 Debug.WriteLine("---"); … … 303 323 protected virtual void SendString(TcpClient tcpClient, string cSendString, string cMult) 304 324 { 325 #if DEBUG 326 Debug.WriteLine("Sending (T:" + Thread.CurrentThread.ManagedThreadId + "): " + cSendString); 327 #endif 305 328 String encodedString = this.EncodeSendString(cSendString, cMult); 306 329 307 330 NetworkStream ns = tcpClient.GetStream(); 308 331 ns.WriteTimeout = this.SendTimeout; 309 byte[] sendBytes = Encoding.ASCII.GetBytes(encodedString);332 byte[] sendBytes = ConnectionEncoding.GetBytes(encodedString); 310 333 ns.Write(sendBytes,0,sendBytes.Length); 311 334 if (this.m_bLogging == true) … … 319 342 private string ReceiveString(TcpClient tcpClient) 320 343 { 321 NetworkStream ns = tcpClient.GetStream(); 344 #if DEBUG 345 Debug.WriteLine("Time At Start of Receive: " + _watch.ElapsedMilliseconds + " ms"); 346 #endif 347 348 NetworkStream ns = tcpClient.GetStream(); 349 ns.ReadTimeout = this.ReceiveTimeout; //Timeout; throw exception automatically if we time out. 350 351 MemoryStream mStream = new MemoryStream(1500); // Auto expanding memory storage for what we receive 352 int numberOfBytesRead = 0; 353 bool bFinished = false; // Have we found the End of Transmission (ASCII 4) yet? 354 355 // Main Read Loop 356 while (!bFinished) //while we are not done 357 { 358 byte[] bReadBuffer = new byte[1500]; //buffer size = MTU. Message MUST be smaller. 359 numberOfBytesRead = ns.Read(bReadBuffer, 0, bReadBuffer.Length); //read data 360 bFinished = FindChar(bReadBuffer, (char)4) > -1; //look for the EOT (ASCII 4) character 361 if (!bFinished) mStream.Write(bReadBuffer, 0, numberOfBytesRead); //if we are not done, put the whole stream in 362 else mStream.Write(bReadBuffer, 0, numberOfBytesRead - 1); //otherwise, number of bytes minus the $C(4) at the end 363 } 364 365 //Read Security S-Packet 366 mStream.Seek(0, SeekOrigin.Begin); 367 int secLength = mStream.ReadByte(); 368 byte[] secBytes = new byte[secLength]; 369 if (secLength > 0) 370 { 371 mStream.Read(secBytes, 0, secLength); 372 } 373 374 //Read Error S-Packet 375 mStream.Seek(secLength + 1, SeekOrigin.Begin); 376 int errLength = mStream.ReadByte(); 377 byte[] errBytes = new byte[errLength]; 378 if (errLength > 0) 379 { 380 mStream.Read(errBytes, 0, errLength); 381 } 382 383 //If either one of these exists, then we have an error on the Mumps Database 384 if (secLength > 0 || errLength > 0) 385 { 386 string errString = ConnectionEncoding.GetString(secBytes); 387 string appString = ConnectionEncoding.GetString(errBytes); 388 throw new BMXNetException("Mumps Database Security/Error: " + errString + " | " + appString); 389 } 390 391 //No Errors. Decode the entire message starting from after the S packets above 392 string sReadBuffer = ConnectionEncoding.GetString(mStream.ToArray(), secLength + errLength + 2, mStream.ToArray().Length - (secLength + errLength + 2)); //decode 393 394 String decodedReceiveString = this.DecodeReceiveString(sReadBuffer); 395 396 if (this.m_bLogging) 397 { 398 Log("Received: " + decodedReceiveString, this.m_LogWriter); 399 } 400 #if DEBUG 401 Debug.WriteLine("Time At End of Receive: " + _watch.ElapsedMilliseconds + " ms"); 402 Debug.WriteLine("Received(T:" + Thread.CurrentThread.ManagedThreadId + "): " + decodedReceiveString.Replace((char)30, (char)10)); 403 #endif 404 return decodedReceiveString; 405 406 407 /* OLD CODE 408 NetworkStream ns = tcpClient.GetStream(); 322 409 ns.ReadTimeout = this.ReceiveTimeout; 323 410 … … 409 496 Log("Received: " + decodedReceiveString, this.m_LogWriter); 410 497 } 498 #if DEBUG 499 Debug.WriteLine("Time At End of Receive: " + _watch.ElapsedMilliseconds + " ms"); 500 #endif 411 501 return decodedReceiveString; 412 502 */ 413 503 } 414 504 … … 422 512 //Build AV Call 423 513 cMSG = ADEBLDMsg(m_cHDR, "BMX AV CODE", winIdentity.Name); 514 #if DEBUG 515 _watch = new Stopwatch(); 516 _watch.Start(); 517 #endif 424 518 SendString(this.Socket, cMSG); 425 426 519 strReceive = ReceiveString(this.Socket); 520 #if DEBUG 521 _watch.Stop(); 522 523 Debug.WriteLine("Time: " + _watch.ElapsedMilliseconds + " ms"); 524 Debug.WriteLine("---"); 525 _watch = null; 526 #endif 527 427 528 sTest = strReceive.Substring(0,3); 428 529 … … 453 554 454 555 cMSG = ADEBLDMsg(m_cHDR, "XUS AV CODE", encryptedAccessVerifyCode); 556 #if DEBUG 557 _watch = new Stopwatch(); 558 _watch.Start(); 559 #endif 455 560 SendString(this.Socket, cMSG); 456 457 561 strReceive = ReceiveString(this.Socket); 562 #if DEBUG 563 _watch.Stop(); 564 565 Debug.WriteLine("Time: " + _watch.ElapsedMilliseconds + " ms"); 566 Debug.WriteLine("---"); 567 _watch = null; 568 #endif 458 569 459 570 if (strReceive.StartsWith("M ERROR=")) … … 519 630 throw new BMXNetException("BMXNetBroker is not connected to RPMS"); 520 631 } 521 632 #if DEBUG 633 _watch = new Stopwatch(); 634 _watch.Start(); 635 #endif 522 636 this.SendString(this.Socket, ADEBLDMsg(m_cHDR, "BMXGetFac", aDuz)); 523 637 return this.ReceiveString(this.Socket); 638 #if DEBUG 639 _watch = new Stopwatch(); 640 _watch.Start(); 641 #endif 642 524 643 } 525 644 catch (BMXNetException bmxEx)
Note:
See TracChangeset
for help on using the changeset viewer.