Skip to content

Commit

Permalink
Fix hang when request node server
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Aug 28, 2020
1 parent 9ae0098 commit 42d99d4
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
4 changes: 3 additions & 1 deletion examples/grpc/helloworld/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
greeter_server
greeter_client
greeter_server
node_modules
51 changes: 51 additions & 0 deletions examples/grpc/helloworld/greeter_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

var PROTO_PATH = __dirname + '../../../protos/helloworld.proto';

var grpc = require('grpc');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
PROTO_PATH,
{keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld;

/**
* Implements the SayHello RPC method.
*/
function sayHello(call, callback) {
callback(null, {message: 'Hello Node Server - ' + call.request.name});
}

/**
* Starts an RPC server that receives requests for the Greeter service at the
* sample server port
*/
function main() {
var server = new grpc.Server();
server.addService(hello_proto.Greeter.service, {sayHello: sayHello});
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
server.start();
}

main();
37 changes: 37 additions & 0 deletions examples/protos/helloworld.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";

package helloworld;

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
6 changes: 5 additions & 1 deletion src/Grpc/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@

class Request extends \Swoole\Http2\Request
{
public $headers = ['content-type' => 'application/grpc'];
public $headers = [
'content-type' => 'application/grpc',
'te' => 'trailers',
'user-agent' => 'grpc-swoole',
];
}

0 comments on commit 42d99d4

Please sign in to comment.