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
ee209935
Commit
ee209935
authored
Aug 20, 2021
by
Dennis Willers
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call setVote with fixed data for testing if socket works.
parent
28440615
Pipeline
#414
passed with stages
in 2 minutes and 48 seconds
Changes
4
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
565 deletions
+80
-565
events.js
events.js
+2
-2
package-lock.json
package-lock.json
+40
-542
package.json
package.json
+2
-3
socket.js
socket.js
+36
-18
No files found.
events.js
View file @
ee209935
...
...
@@ -147,7 +147,7 @@ function createRouter(db) {
const
average
=
results
[
0
].
average
;
const
votes
=
results
[
0
].
votes
;
if
(
average
!==
null
&&
votes
!==
null
)
{
res
.
header
(
'
Access-Control-Allow-Origin
'
,
"
*
"
).
status
(
5
00
).
json
({
votes
:
votes
,
average
:
average
,
vote
:
vote
});
res
.
header
(
'
Access-Control-Allow-Origin
'
,
"
*
"
).
status
(
2
00
).
json
({
votes
:
votes
,
average
:
average
,
vote
:
vote
});
return
;
}
}
...
...
@@ -195,7 +195,7 @@ function createRouter(db) {
// the routes are defined here
router
.
get
(
'
/test
'
,
[
test
]);
router
.
post
(
'
/
addMap
'
,
[
hasMap
,
hasVote
,
getMapInfo
]);
router
.
post
(
'
/
setVote
'
,
[
hasMap
,
hasVote
,
getMapInfo
]);
router
.
post
(
'
/getMapInfo
'
,
[
getVote
]);
return
router
;
...
...
package-lock.json
View file @
ee209935
This diff is collapsed.
Click to expand it.
package.json
View file @
ee209935
...
...
@@ -12,11 +12,10 @@
"author"
:
"Dennis Willers"
,
"license"
:
"
ISC
"
,
"dependencies"
:
{
"
axios
"
:
"
^0.21.1
"
,
"
cors
"
:
"
^2.8.5
"
,
"
express
"
:
"
^4.17.1
"
,
"
mysql
"
:
"
^2.18.1
"
,
"
socket.io
"
:
"
^3.0.4
"
,
"
socket.io-client
"
:
"
^3.0.4
"
"
mysql
"
:
"
^2.18.1
"
},
"devDependencies"
:
{
"
nodemon
"
:
"
^2.0.7
"
...
...
socket.js
View file @
ee209935
var
net
=
require
(
'
net
'
);
const
axios
=
require
(
'
axios
'
);
// creates the server
var
server
=
net
.
createServer
();
...
...
@@ -57,25 +58,32 @@ server.on('connection',function(socket){
console
.
log
(
'
Socket timed out
'
);
});
socket
.
on
(
'
map
'
,
function
(
data
)
{
console
.
log
(
'
MAP Client Connect to:
'
,
data
);
});
socket
.
on
(
'
data
'
,
function
(
data
){
var
bread
=
socket
.
bytesRead
;
var
bwrite
=
socket
.
bytesWritten
;
console
.
log
(
'
Bytes read :
'
+
bread
);
console
.
log
(
'
Bytes written :
'
+
bwrite
);
console
.
log
(
'
Data sent to server :
'
+
data
);
axios
.
post
(
'
http://localhost:8080/setVote
'
,
{
mapId
:
'
abcdef
'
,
name
:
'
alphabet
'
,
userId
:
'
xyz
'
,
vote
:
'
30
'
})
.
then
(
res
=>
{
console
.
log
(
'
Prepare:
'
,
res
.
headers
,
res
.
data
);
//echo data
var
is_kernel_buffer_full
=
socket
.
write
(
'
FROMSERVER:
'
+
data
);
var
is_kernel_buffer_full
=
socket
.
write
(
'
FROMSERVER:
'
+
JSON
.
stringify
(
res
.
headers
)
+
JSON
.
stringify
(
res
.
data
)
);
if
(
is_kernel_buffer_full
){
console
.
log
(
'
Data was flushed successfully from kernel buffer i.e written successfully!
'
);
}
else
{
socket
.
pause
();
}
})
.
catch
(
error
=>
{
console
.
error
(
error
)
});
});
socket
.
on
(
'
drain
'
,
function
(){
...
...
@@ -207,21 +215,31 @@ client.on('data',function(data){
// u can also => write the below code in seperate js file
// open new node instance => and run it...
/*const clients = net.connect({port: 3000}, () => {
// 'connect' 3201
// 87.78.129.86
const
clients
=
net
.
connect
({
host
:
'
localhost
'
,
port
:
3000
},
()
=>
{
console
.
log
(
'
connected to server!
'
);
clients.write('world!\r\n');
clients
.
write
(
'
Hello World Client!
\r\n
'
);
//test(clients);
});
clients
.
on
(
'
data
'
,
(
data
)
=>
{
console
.
log
(
data
.
toString
());
clients
.
end
();
});
clients.on('end', () => {
/*
clients.on('end', () => {
console.log('disconnected from server');
});
//*/
async
function
test
(
clients
)
{
let
i
=
0
;
while
(
true
)
{
await
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
5000
));
i
=
i
+
1
;
clients
.
write
(
"
Test:
"
+
i
);
}
}
// ---------------------------------------------- //
...
...
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