Assembly: Quanser.Communications (in Quanser.Communications.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Function Accept ( _ sendBufferSize As Integer, _ receiveBufferSize As Integer _ ) As Stream |
C# |
---|
public Stream Accept( int sendBufferSize, int receiveBufferSize ) |
Visual C++ |
---|
public: Stream^ Accept( int sendBufferSize, int receiveBufferSize ) |
JavaScript |
---|
function accept(sendBufferSize, receiveBufferSize); |
Parameters
- sendBufferSize
- Type: System..::.Int32
The size of the buffer to use for sending data over the client stream, in bytes. This buffer is referred to as the stream send buffer in this documentation.
- receiveBufferSize
- Type: System..::.Int32
The size of the buffer to use for receiveing data over the client stream, in bytes. This buffer is referred to as the stream receive buffer in this documentation.
Return Value
This method returns a Stream object representing a new connection to the client if the connection is established. If non-blocking I/O is being used, then it may also return nullptr, which indicates that no client connection was pending. Use the Poll(Timeout, Int32) method with the Accept flag to determine when a client connection is pending.Remarks
This method accepts a connection to a listening communication stream by a client. The client connects using one of the Connect methods.
If the Listen method that created the stream was called with nonBlocking flag set to false then this call will block until a client connects. The client stream returned will also be a blocking stream.
If the Listen method that created the stream was called with nonBlocking flag set to true then this call will not block. If there is no pending client connection then it will return a nullptr (or System.DBNull in Visual Basic). The Poll(Timeout, Int32) method may be used with the Accept flag to determine when a client connection is pending. In this case, the client stream returned will also be a non-blocking stream.
Examples
C# | Copy Code |
---|---|
Stream server = new Stream(); String uri = "tcpip://localhost:18000"; int sendBufferSize = 1024; int receiveBufferSize = 1024; bool done = false; Stream client; try { server.Listen(uri); try { while (!done) { client = server.Accept(sendBufferSize, receiveBufferSize); /* ... 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 sendBufferSize As Integer = 1024; Dim receiveBufferSize As Integer = 1024; Dim done As Boolean = False Dim client As Stream Try server.Listen(uri) Try While Not done Do client = server.Accept(sendBufferSize, receiveBufferSize) ' ... 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"; int sendBufferSize = 1024; int receiveBufferSize = 1024; bool done = false; Stream^ client; try { server->Listen(uri); try { while (!done) { client = server->Accept(sendBufferSize, receiveBufferSize); /* ... 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); } |
Exceptions
Exception | Condition |
---|---|
Quanser.Communications..::.StreamException | If the connection cannot be accepted then an exception is thrown. This situation typically arises if the Accept method is called on a connected stream rather than a listening stream. |