new Server(optionsopt)
Constructs a server object that stores request handlers and delegates incoming requests to those handlers
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
options |
Object |
<optional> |
Options that should be passed to the internal server implementation |
- Source:
Example
var server = new grpc.Server();
server.addProtoService(protobuf_service_descriptor, service_implementation);
server.bind('address:port', server_credential);
server.start();
Members
addProtoService
Add a proto service to the server, with a corresponding implementation
- Deprecated:
- Use grpc.Server#addService instead
- Source:
Methods
addService(service, implementation)
Add a service to the server, with a corresponding implementation.
Parameters:
| Name | Type | Description |
|---|---|---|
service |
grpc~ServiceDefinition | The service descriptor |
implementation |
Object.<String, grpc.Server~handleCall> | Map of method names to method implementation for the provided service. |
- Source:
bind(port, creds)
Binds the server to the given port, with SSL disabled if creds is an insecure credentials object
Parameters:
| Name | Type | Description |
|---|---|---|
port |
string | The port that the server should bind on, in the format "address:port" |
creds |
grpc.ServerCredentials | Server credential object to be used for SSL. Pass an insecure credentials object for an insecure port. |
- Source:
forceShutdown()
Forcibly shuts down the server. The server will stop receiving new calls and cancel all pending calls. When it returns, the server has shut down. This method is idempotent with itself and tryShutdown, and it will trigger any outstanding tryShutdown callbacks.
- Source:
register(name, handler, serialize, deserialize, type) → {boolean}
Registers a handler to handle the named method. Fails if there already is a handler for the given method. Returns true on success
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The name of the method that the provided function should handle/respond to. |
handler |
grpc.Server~handleCall | Function that takes a stream of request values and returns a stream of response values |
serialize |
grpc~serialize | Serialization function for responses |
deserialize |
grpc~deserialize | Deserialization function for requests |
type |
string | The streaming type of method that this handles |
- Source:
Returns:
True if the handler was set. False if a handler was already set for that name.
- Type
- boolean
start()
Start the server and begin handling requests
- Source:
tryShutdown(callback)
Gracefully shuts down the server. The server will stop receiving new calls, and any pending calls will complete. The callback will be called when all pending calls have completed and the server is fully shut down. This method is idempotent with itself and forceShutdown.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | The shutdown complete callback |
- Source:
Type Definitions
handleBidiStreamingCall(call)
User provided method to handle bidirectional streaming calls on the server.
Parameters:
| Name | Type | Description |
|---|---|---|
call |
grpc~ServerDuplexStream | The call object |
- Source:
handleCall
Unified type for application handlers for all types of calls
Type:
- grpc.Server~handleUnaryCall | grpc.Server~handleClientStreamingCall | grpc.Server~handleServerStreamingCall | grpc.Server~handleBidiStreamingCall
- Source:
handleClientStreamingCall(call, callback)
User provided method to handle client streaming methods on the server.
Parameters:
| Name | Type | Description |
|---|---|---|
call |
grpc~ServerReadableStream | The call object |
callback |
grpc.Server~sendUnaryData | The callback to call to respond to the request |
- Source:
handleServerStreamingCall(call)
User provided method to handle server streaming methods on the server.
Parameters:
| Name | Type | Description |
|---|---|---|
call |
grpc~ServerWritableStream | The call object |
- Source:
handleUnaryCall(call, callback)
User-provided method to handle unary requests on a server
Parameters:
| Name | Type | Description |
|---|---|---|
call |
grpc~ServerUnaryCall | The call object |
callback |
grpc.Server~sendUnaryData | The callback to call to respond to the request |
- Source:
sendUnaryData(error, value, traileropt, flagsopt)
Callback function passed to server handlers that handle methods with unary responses.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
error |
grpc~ServiceError | An error, if the call failed |
|
value |
* | The response value. Must be a valid argument to the
|
|
trailer |
grpc.Metadata |
<optional> |
Trailing metadata to send, if applicable |
flags |
grpc.writeFlags |
<optional> |
Flags to modify writing the response |
- Source: