Add some real messages to ASN.1 and handle pings on server
This commit is contained in:
parent
fe8b1ef977
commit
cdbef62e70
1
server/.gitignore
vendored
1
server/.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
_build/*
|
_build/*
|
||||||
*.beam
|
*.beam
|
||||||
src/StudySystemProtocol.erl
|
src/StudySystemProtocol.erl
|
||||||
|
include/*
|
||||||
|
@ -1,11 +1,40 @@
|
|||||||
StudySystemProtocol DEFINITIONS EXPLICIT TAGS ::= BEGIN
|
StudySystemProtocol DEFINITIONS EXPLICIT TAGS ::= BEGIN
|
||||||
|
|
||||||
|
ActivityType ::= ENUMERATED {
|
||||||
|
reading(0),
|
||||||
|
exercises(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
Session ::= SEQUENCE {
|
||||||
|
subjectId INTEGER,
|
||||||
|
type ActivityType,
|
||||||
|
timestamp INTEGER,
|
||||||
|
minutes INTEGER
|
||||||
|
}
|
||||||
|
|
||||||
Request ::= CHOICE {
|
Request ::= CHOICE {
|
||||||
foo [0] NULL
|
ping [0] NULL,
|
||||||
|
listPrioritizedActivities [1] NULL,
|
||||||
|
logSession [2] Session
|
||||||
|
}
|
||||||
|
|
||||||
|
PrioritizedActivity ::= SEQUENCE {
|
||||||
|
subjectId INTEGER,
|
||||||
|
subjectName UTF8String,
|
||||||
|
type ActivityType,
|
||||||
|
priority INTEGER
|
||||||
|
}
|
||||||
|
|
||||||
|
Error ::= ENUMERATED {
|
||||||
|
invalidRequest(0),
|
||||||
|
invalidArguments(1),
|
||||||
|
serverError(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
Response ::= CHOICE {
|
Response ::= CHOICE {
|
||||||
msg [0] UTF8String
|
error [0] Error,
|
||||||
|
ack [1] NULL,
|
||||||
|
prioritizedActivities [2] SEQUENCE OF PrioritizedActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
END
|
END
|
||||||
|
@ -23,13 +23,14 @@ handle_cast(_Msg, State) ->
|
|||||||
|
|
||||||
handle_info({ssl, Socket, Data}, State) ->
|
handle_info({ssl, Socket, Data}, State) ->
|
||||||
case 'StudySystemProtocol':decode('Request', Data) of
|
case 'StudySystemProtocol':decode('Request', Data) of
|
||||||
{ok, {foo, _}} ->
|
{ok, {ping, _}} ->
|
||||||
{ok, Encoded}
|
{ok, Encoded} = 'StudySystemProtocol':encode(
|
||||||
= 'StudySystemProtocol':encode('Response', {msg, "Foo"}),
|
'Response', {ack, 'NULL'}),
|
||||||
ok = ssl:send(Socket, Encoded);
|
ok = ssl:send(Socket, Encoded);
|
||||||
Result ->
|
{error, {asn1, _Reason}} ->
|
||||||
io:format("Invalid message: ~p~n", [Result]),
|
{ok, Encoded} = 'StudySystemProtocol':encode(
|
||||||
ok
|
'Response', {error, invalidRequest}),
|
||||||
|
ok = ssl:send(Socket, Encoded)
|
||||||
end,
|
end,
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({ssl_closed, _Socket}, State) ->
|
handle_info({ssl_closed, _Socket}, State) ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user