Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Voting
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dennis Willers
Voting
Commits
d7b249f7
Commit
d7b249f7
authored
Aug 20, 2021
by
Dennis Willers
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Response Logik for socket. Should give now real responses.
parent
58ce6b0e
Pipeline
#421
passed with stages
in 2 minutes and 47 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
20 deletions
+64
-20
helpFunctions.js
helpFunctions.js
+37
-0
socket.js
socket.js
+27
-20
No files found.
helpFunctions.js
0 → 100644
View file @
d7b249f7
const
axios
=
require
(
'
axios
'
);
/**
* @return {boolean}
*/
function
isJsonString
(
str
)
{
try
{
JSON
.
parse
(
str
);
}
catch
(
e
)
{
return
false
;
}
return
true
;
}
function
checkIfRequestHasVote
(
json
)
{
return
json
.
hasOwnProperty
(
'
vote
'
);
}
function
sendRequest
(
url
,
json
,
callback
)
{
//make post request
axios
.
post
(
url
,
JSON
.
parse
(
json
))
.
then
(
res
=>
{
//echo data
callback
(
res
);
})
.
catch
(
error
=>
{
console
.
error
(
error
);
callback
(
null
);
});
}
module
.
exports
=
{
isJsonString
,
checkIfRequestHasVote
,
sendRequest
};
socket.js
View file @
d7b249f7
var
net
=
require
(
'
net
'
);
var
net
=
require
(
'
net
'
);
const
axios
=
require
(
'
axio
s
'
);
var
hf
=
require
(
'
./helpFunction
s
'
);
// creates the server
// creates the server
var
server
=
net
.
createServer
();
var
server
=
net
.
createServer
();
...
@@ -73,25 +73,27 @@ server.on('connection',function(socket){
...
@@ -73,25 +73,27 @@ server.on('connection',function(socket){
console
.
log
(
'
Bytes read :
'
+
bread
);
console
.
log
(
'
Bytes read :
'
+
bread
);
console
.
log
(
'
Bytes written :
'
+
bwrite
);
console
.
log
(
'
Bytes written :
'
+
bwrite
);
console
.
log
(
'
Data sent to server :
'
+
data
);
console
.
log
(
'
Data sent to server :
'
+
data
);
axios
.
post
(
'
http://localhost:8080/setVote
'
,
{
if
(
hf
.
isJsonString
(
data
))
{
mapId
:
'
abcdef
'
,
let
url
;
name
:
'
alphabet
'
,
if
(
hf
.
checkIfRequestHasVote
(
data
))
{
userId
:
'
xyz
'
,
url
=
'
http://localhost:8080/setVote
'
;
vote
:
'
30
'
}
else
{
})
url
=
'
http://localhost:8080/getMapInfo
'
;
.
then
(
res
=>
{
}
//echo data
hf
.
sendRequest
(
url
,
data
,
res
=>
{
var
is_kernel_buffer_full
=
socket
.
write
(
JSON
.
stringify
(
res
.
data
)
+
'
\n
'
);
if
(
res
)
{
if
(
is_kernel_buffer_full
){
var
is_kernel_buffer_full
=
socket
.
write
(
JSON
.
stringify
(
res
.
data
)
+
'
\n
'
);
console
.
log
(
'
Data was flushed successfully from kernel buffer i.e written successfully!
'
);
if
(
is_kernel_buffer_full
){
}
else
{
console
.
log
(
'
Data was flushed successfully from kernel buffer i.e written successfully!
'
);
socket
.
pause
();
}
else
{
socket
.
pause
();
}
}
else
{
console
.
log
(
"
Res was null
"
);
}
}
})
.
catch
(
error
=>
{
console
.
error
(
error
)
});
});
}
});
});
socket
.
on
(
'
drain
'
,
function
(){
socket
.
on
(
'
drain
'
,
function
(){
...
@@ -236,9 +238,14 @@ client.on('data',function(data){
...
@@ -236,9 +238,14 @@ client.on('data',function(data){
// 87.78.129.86 | localhost
// 87.78.129.86 | localhost
const
testClient
=
net
.
connect
({
host
:
'
87.78.129.86
'
,
port
:
3201
},
()
=>
{
const
testClient
=
net
.
connect
({
host
:
'
localhost
'
,
port
:
3000
},
()
=>
{
console
.
log
(
'
connected to server!
'
);
console
.
log
(
'
connected to server!
'
);
testClient
.
write
(
'
Hello World Client!
\r\n
'
);
//testClient.write('Hello World Client!\r\n');
testClient
.
write
(
JSON
.
stringify
({
"
mapId
"
:
"
keineBekannteMap1
"
,
"
name
"
:
"
keinBekannterMapName1
"
,
"
userId
"
:
"
keinBekannterUser1
"
}));
//test(testClient);
//test(testClient);
});
});
...
...
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