Skip to content

Commit 42d99d4

Browse files
committed
Fix hang when request node server
1 parent 9ae0098 commit 42d99d4

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
greeter_server
1+
greeter_client
2+
greeter_server
3+
node_modules
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
*
3+
* Copyright 2015 gRPC authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
var PROTO_PATH = __dirname + '../../../protos/helloworld.proto';
20+
21+
var grpc = require('grpc');
22+
var protoLoader = require('@grpc/proto-loader');
23+
var packageDefinition = protoLoader.loadSync(
24+
PROTO_PATH,
25+
{keepCase: true,
26+
longs: String,
27+
enums: String,
28+
defaults: true,
29+
oneofs: true
30+
});
31+
var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld;
32+
33+
/**
34+
* Implements the SayHello RPC method.
35+
*/
36+
function sayHello(call, callback) {
37+
callback(null, {message: 'Hello Node Server - ' + call.request.name});
38+
}
39+
40+
/**
41+
* Starts an RPC server that receives requests for the Greeter service at the
42+
* sample server port
43+
*/
44+
function main() {
45+
var server = new grpc.Server();
46+
server.addService(hello_proto.Greeter.service, {sayHello: sayHello});
47+
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
48+
server.start();
49+
}
50+
51+
main();

examples/protos/helloworld.proto

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2015 gRPC authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
option java_multiple_files = true;
18+
option java_package = "io.grpc.examples.helloworld";
19+
option java_outer_classname = "HelloWorldProto";
20+
21+
package helloworld;
22+
23+
// The greeting service definition.
24+
service Greeter {
25+
// Sends a greeting
26+
rpc SayHello (HelloRequest) returns (HelloReply) {}
27+
}
28+
29+
// The request message containing the user's name.
30+
message HelloRequest {
31+
string name = 1;
32+
}
33+
34+
// The response message containing the greetings
35+
message HelloReply {
36+
string message = 1;
37+
}

src/Grpc/Request.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88

99
class Request extends \Swoole\Http2\Request
1010
{
11-
public $headers = ['content-type' => 'application/grpc'];
11+
public $headers = [
12+
'content-type' => 'application/grpc',
13+
'te' => 'trailers',
14+
'user-agent' => 'grpc-swoole',
15+
];
1216
}

0 commit comments

Comments
 (0)