Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
grpc_examples
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gabriele Civitarese
grpc_examples
Commits
8b056be6
Commit
8b056be6
authored
Apr 04, 2019
by
Gabriele Civitarese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Esempietto di comunicazione ProtocolBuffer su socket
parent
c7004263
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
0 deletions
+75
-0
Client.java
src/main/java/researcher/Client.java
+30
-0
Server.java
src/main/java/researcher/Server.java
+24
-0
Researcher.proto
src/main/proto/Researcher.proto
+21
-0
No files found.
src/main/java/researcher/Client.java
0 → 100644
View file @
8b056be6
package
researcher
;
import
it.ewlab.researcher.ResearcherOuterClass.Researcher
;
import
java.io.IOException
;
import
java.net.Socket
;
public
class
Client
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
Socket
s
=
new
Socket
(
"localhost"
,
9999
);
Researcher
r
=
Researcher
.
newBuilder
()
.
setName
(
"Gabriele"
)
.
setSurname
(
"Civitarese"
)
.
setType
(
Researcher
.
ResearcherType
.
POSTDOC
)
.
addPaper
(
Researcher
.
Paper
.
newBuilder
().
setTitle
(
"Activity Recognition"
)
.
setYear
(
2014
))
.
addPaper
(
Researcher
.
Paper
.
newBuilder
().
setTitle
(
"Activity Recognition Again"
)
.
setYear
(
2015
)).
build
();
r
.
writeTo
(
s
.
getOutputStream
());
s
.
close
();
}
}
src/main/java/researcher/Server.java
0 → 100644
View file @
8b056be6
package
researcher
;
import
it.ewlab.researcher.ResearcherOuterClass
;
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
public
class
Server
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
ServerSocket
serverSocket
=
new
ServerSocket
(
9999
);
Socket
s
=
serverSocket
.
accept
();
ResearcherOuterClass
.
Researcher
r
=
ResearcherOuterClass
.
Researcher
.
parseFrom
(
s
.
getInputStream
());
System
.
out
.
println
(
r
);
}
}
src/main/proto/Researcher.proto
0 → 100644
View file @
8b056be6
package
it
.
ewlab.researcher
;
message
Researcher
{
required
string
name
=
1
;
required
string
surname
=
2
;
enum
ResearcherType
{
PHDSTUDENT
=
0
;
POSTDOC
=
1
;
ASSISTANTPROFESSOR
=
2
;
}
message
Paper
{
required
string
title
=
1
;
required
int32
year
=
2
;
}
repeated
Paper
paper
=
3
;
optional
ResearcherType
type
=
4
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment