Constructs a Stream object. The stream is not connected or
listening.
Namespace:
Quanser.CommunicationsAssembly: Quanser.Communications (in Quanser.Communications.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub New |
C# |
---|
public Stream() |
Visual C++ |
---|
public: Stream() |
JavaScript |
---|
Quanser.Communications.Stream = function(); |
Remarks
One of the Connect or Listen methods must be called prior to using any other methods of this object.
Examples
This example listens on TCP/IP port 18000 for a connection from a client.
C# | Copy Code |
---|---|
Stream server = new Stream(); String uri = "tcpip://localhost:18000"; bool done = false; Stream client; try { server.Listen(uri, false); try { while (!done) { client = server.Accept(); /* ... communicate with client ... */ client.Close(); } } catch (Exception ex) { Console.WriteLine("Error communicating with client on URI '" + uri + "'. " + ex); } server.Close(); } catch (Exception ex) { Console.WriteLine("Unable to listen on URI '" + uri + "'. " + ex); } |
Visual Basic | Copy Code |
---|---|
Dim server As New Stream() Dim uri As String = "tcpip://localhost:18000" Dim done As Boolean = False Dim client As Stream Try server.Listen(uri, false) Try While Not done Do client = server.Accept() ' ... communicate with client ... client.Close() End While Catch ex As Exception Console.WriteLine("Error communicating with client on URI '" & uri & "'. " & ex.ToString()) End Try server.Close() Catch ex As Exception Console.WriteLine("Unable to listen on URI '" & uri & "'. " & ex.ToString()) End Try |
Visual C++ | Copy Code |
---|---|
Stream^ server = gcnew Stream(); String^ uri = L"tcpip://localhost:18000"; bool done = false; Stream^ client; try { server->Listen(uri, false); try { while (!done) { client = server->Accept(); /* ... communicate with client ... */ client->Close(); } } catch (Exception ex) { Console::WriteLine(L"Error communicating with client on URI '" + uri + "'. " + ex); } server->Close(); } catch (Exception ex) { Console::WriteLine(L"Unable to listen on URI '" + uri + "'. " + ex); } |