-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·45 lines (36 loc) · 942 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var express = require("express")
var app = express()
var socket = require("nodejs-websocket")
var fs = require("fs")
var yml=fs.readFileSync('test.yml')
var stream ;
var server = socket.createServer(function (conn){
var input="";
// console.log("new connection")
conn.on('connect',function(){
console.log("connnection accepted")
})
conn.on("text",function (str){
// console.log("recieved\n"+str)
// conn.sendText(str.toUpperCase()+"#")
if(str.startsWith("...###...###>>>")){
stream = fs.createWriteStream(str.substring(15));
}else{
input=input+str;
}
})
conn.on("error",function(error){
console.log("error" +error)
})
//conn.sendBinary(yml)
conn.on("close",function(code,reason){
stream.write(input)
console.log("connection closed\n"+reason)
//console.log(input)
stream.end()
})
}).listen(8001)
app.get("/getLoc",function(req,res){
res.send('patna.bihta.kanpur.up')
})
app.listen(8009)