public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader br = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); br = new BinaryReader(ns); Int64 iTemp; for (int i = 0; i < i64Arr.Length; i++) { iTemp = br.ReadInt64(); if (iTemp != i64Arr[i]) { iCountErrors++; Console.WriteLine("Error_5453c_" + i + "! Expected==" + i64Arr[i] + ", got==" + iTemp); } } Console.WriteLine("We are done with the listening"); ns.Close(); } catch (Exception e) { iCountErrors++; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (br != null) { br.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BufferedStream bs = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BufferedStream(ns); int iByte; for (int i = 0; i < 100; i++) { iByte = bs.ReadByte(); if (iByte != i) { iCountErrors++; Console.WriteLine("Error_4324! Expected==" + i + ", got==" + iByte); } } Console.WriteLine("We are done with the listening"); } catch (Exception e) { iCountErrors++; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (bs != null) { bs.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader br = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); br = new BinaryReader(ns); for (int iLoop = 0; iLoop < chArrValues.Length; iLoop++) { Byte[] bytArr = new Byte[2]; int i32 = br.Read(bytArr, 0, bytArr.Length); if (i32 > 2) { iCountErrors++; Console.WriteLine("Error_4353! Incorrect number of chars read, read==" + i32); } } Console.WriteLine("We are done with the listening"); } catch (Exception e) { iCountErrors++; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (br != null) { br.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader br = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); br = new BinaryReader(ns); Int32 tmp = 0; for (int i = 0; i < chArr.Length; i++) { tmp = br.PeekChar(); if (tmp != -1) { iCountErrors++; Console.WriteLine("It's a network stream.... We always expect -1... but the real value..." + tmp); } br.Read(); } Console.WriteLine("We are done with the listening"); } catch (Exception e) { Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (br != null) { br.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; StreamReader sr = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); sr = new StreamReader(ns); int iBytValue = 0, iExpected = 65; for (int iLoop = 0; iLoop < 4; iLoop++) { iBytValue = sr.Read(); if (iBytValue != iExpected++) { iCountErrors++; Console.WriteLine("Error_66677! Incorrect character read"); } } Console.WriteLine("We are done with the listening"); } catch (Exception e) { iCountErrors++; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (sr != null) { sr.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = null; Socket s = null; NetworkStream ns = null; StreamReader sr = null; try { listener = new TcpThreadListener(0); listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); s = listener.AcceptSocket(); ns = new NetworkStream(s); sr = new StreamReader(ns, enc, detectEncodingFromByteOrderMarks, 100); String strRead = sr.ReadLine(); Console.WriteLine("read string..." + strRead); if (strRead != strResult) { iCountErrors++; Console.WriteLine("Error_66677! Incorrect string read"); } ns.Close(); } catch (Exception e) { iCountErrors++; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (sr != null) { sr.Close(); } } }
public static void StartListeningTcp() { TcpThreadListener listener = null; Socket s = null; NetworkStream ns = null; BinaryReader bs = null; try { listener = new TcpThreadListener(0); listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BinaryReader(ns, enc); Console.WriteLine(enc.ToString()); int iNumBytesRead = bs.Read(new Byte[1024], 0, 1024); if (iNumBytesRead != 1024) { iCountErrors++; } } catch (Exception e) { Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (bs != null) { bs.Close(); } } }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader bs = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BinaryReader(ns); if (bs.BaseStream != ns) { Console.WriteLine("Unexpected base stream"); iCountErrors++; } } catch (Exception e) { Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (bs != null) { bs.Close(); } } //finally }
public static void StartListeningTcp() { //Use 0 to cause socket to use a free port number. TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader bs = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BinaryReader(ns); Console.WriteLine(bs.Read(new Byte[1024], 0, 1024)); } catch (Exception e) { Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (bs != null) { bs.Close(); } } //finally }
public static void StartListeningTcp() { //Use 0 to cause socket to use a free port number. TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader bs = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BinaryReader( ns ); Console.WriteLine( bs.Read(new Byte[1024], 0, 1024) ); } catch(Exception e) { Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(bs != null) { bs.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BufferedStream bs = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BufferedStream( ns ); bs.Close(); try { bs.Flush(); iCountErrors++; Console.WriteLine( "Error_8989!!! Expected exception not occured"); } catch (ObjectDisposedException iexc) { Console.WriteLine( "Info_9898! Caught expected exception, exc=="+iexc.Message); } catch (Exception exc) { iCountErrors++; Console.WriteLine( "Error_0000! Incorrect exception thrown, exc=="+exc.ToString()); } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(bs != null) { bs.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader br = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); br = new BinaryReader( ns ); SByte iTemp ; for(int i = 0 ; i < sbArr.Length ; i++) { iTemp = br.ReadSByte(); if(iTemp != sbArr[i]) { iCountErrors++; Console.WriteLine( "Error_0000_"+i+"! Expected=="+sbArr[i]+", got=="+iTemp); } } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(br != null) { br.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader br = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); br = new BinaryReader( ns ); Int64 iTemp; Int64 iVal; for( int iLoop = 0 ; iLoop < chArrValues.Length ; iLoop++ ) { iVal = (Int64)(byte)chArrValues[iLoop] + (1<<8) * (Int64)(byte)chArrValues[(iLoop+1) % chArrValues.Length] + (1<<16) * (Int64)(byte)chArrValues[(iLoop+2) % chArrValues.Length] + (1<<24) * (Int64)(byte)chArrValues[(iLoop+3) % chArrValues.Length]; iTemp = br.ReadInt64(); if(iTemp != iVal) { iCountErrors++; Console.WriteLine( "Error_5453c_"+iLoop+"! Expected=="+iVal+", got=="+iTemp); } } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(br != null) { br.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; StreamReader sr = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); sr = new StreamReader(ns); try { Int32 tmp = 0; for(int i = 0 ; i < chArr.Length ; i++) { if((tmp = sr.Read()) != (Int32)chArr[i]) { iCountErrors++; Console.WriteLine( "Error_9090_"+i+"! Expected=="+(Int32)chArr[i]+", got=="+tmp); } } } catch (Exception exc) { iCountErrors++; Console.WriteLine( "Error_5555! Incorrect exception thrown, exc=="+exc.ToString()); } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(sr != null) { sr.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; StreamReader sr = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); sr = new StreamReader(ns); int iBytValue = 0 , iExpected = 65; for(int iLoop = 0 ; iLoop < 4 ; iLoop++){ iBytValue = sr.Read(); if(iBytValue != iExpected++) { iCountErrors++; Console.WriteLine( "Error_66677! Incorrect character read"); } } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(sr != null) { sr.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = null; Socket s = null; NetworkStream ns = null; StreamReader sr = null; try { listener = new TcpThreadListener(0); listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); s = listener.AcceptSocket(); ns = new NetworkStream(s); sr = new StreamReader(ns , enc, detectEncodingFromByteOrderMarks); String strRead = sr.ReadLine(); Console.WriteLine("read string..." + strRead ); if(strRead != strResult) { iCountErrors++; Console.WriteLine( "Error_66677! Incorrect string read"); } } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(sr != null) { sr.Close(); } } }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader bs = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BinaryReader( ns); if ( bs.BaseStream != ns) { Console.WriteLine("Unexpected base stream"); iCountErrors++ ; } } catch(Exception e) { Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(bs != null) { bs.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; StreamReader sr = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); sr = new StreamReader(ns); try { String text = sr.ReadLine(); if(text != strValue) { iCountErrors++; Console.WriteLine( "Unexpected text in the stream..." + text); } } catch (Exception exc) { iCountErrors++; Console.WriteLine( "Error_5555! Incorrect exception thrown, exc=="+exc.ToString()); } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(sr != null) { sr.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; StreamReader sr = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint)listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); sr = new StreamReader(ns); try { Char[] chArr = new Char[chArrValues.Length]; int iNumChars = sr.Read(chArr, 0, chArr.Length); if (iNumChars != chArrValues.Length) { iCountErrors++; Console.WriteLine("Error_54543! Incorrect number of chars read, read==" + iNumChars); } for (int i = 0; i < chArr.Length; i++) { if (chArr[i] != chArrValues[i]) { iCountErrors++; Console.WriteLine("Error_8690_" + i + "! Incorrect character, expected==" + chArrValues[i] + ", got==" + chArr[i]); } } } catch (Exception exc) { iCountErrors++; Console.WriteLine("Error_5555! Incorrect exception thrown, exc==" + exc.ToString()); } Console.WriteLine("We are done with the listening"); } catch (Exception e) { iCountErrors++; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if (sr != null) { sr.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader br = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); br = new BinaryReader( ns ); Int32 tmp = 0; for(int i = 0 ; i < chArr.Length ; i++) { tmp = br.PeekChar(); if(tmp != -1) { iCountErrors++; Console.WriteLine( "It's a network stream.... We always expect -1... but the real value..." + tmp); } br.Read(); } Console.WriteLine("We are done with the listening"); } catch(Exception e) { Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(br != null) { br.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader br = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); br = new BinaryReader( ns ); Byte[] bArrReturn = br.ReadBytes(bInputBytes.Length); if(bArrReturn.Length != bInputBytes.Length) { iCountErrors++; Console.WriteLine( "Error_1900c! Incorrect number of chars read"); } for(int i = 0 ; i < bInputBytes.Length ; i++) { if(bArrReturn[i] != bInputBytes[i]) { iCountErrors++; Console.WriteLine( "Error_298vc_"+i+"! Expected=="+(Int32)bInputBytes[i]+", got=="+(Int32)bArrReturn[i]); } } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(br != null) { br.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BufferedStream bs = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BufferedStream( ns ); int iByte ; for(int i = 0 ; i < 100 ; i++) { iByte = bs.ReadByte (); if(iByte != i) { iCountErrors++; Console.WriteLine( "Error_4324! Expected=="+i+", got=="+iByte); } } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(bs != null) { bs.Close(); } } //finally }
public static void StartListeningTcp() { TcpThreadListener listener = null; Socket s = null; NetworkStream ns = null; BinaryReader bs = null; try { listener = new TcpThreadListener(0); listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); s = listener.AcceptSocket(); ns = new NetworkStream(s); bs = new BinaryReader( ns , enc); Console.WriteLine( enc.ToString() ); int iNumBytesRead = bs.Read(new Byte[1024], 0, 1024) ; if ( iNumBytesRead != 1024 ) iCountErrors++ ; } catch(Exception e) { Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(bs != null) { bs.Close(); } } }
public static void StartListeningTcp() { TcpThreadListener listener = new TcpThreadListener(0); NetworkStream ns = null; BinaryReader br = null; try { listener.Start(); IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint; Interlocked.Exchange(ref iPortNumber, ipe.Port); Console.WriteLine("Using port: {0}", iPortNumber); m_PortSetEvent.Set(); Socket s = listener.AcceptSocket(); ns = new NetworkStream(s); br = new BinaryReader( ns ); Char[] charArr = new Char[chArr.Length]; int i32 = br.Read(charArr, 0, charArr.Length); if(i32 != chArr.Length ) { iCountErrors++; Console.WriteLine( "Error_4353! Incorrect number of chars read, read=="+i32); } for(int i = 0 ; i < chArr.Length ; i++) { if(charArr[i] != chArr[i]) { iCountErrors++; Console.WriteLine( "Error_58byc_"+i+"! Incorrect character, expected=="+chArr[i]+", got=="+charArr[i]); } } Console.WriteLine("We are done with the listening"); } catch(Exception e) { iCountErrors++ ; Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace); m_PortSetEvent.Set(); } finally { if (listener != null) { listener.Stop(); } if (ns != null) { ns.Close(); } if(br != null) { br.Close(); } } //finally }