aboutsummaryrefslogtreecommitdiff
path: root/websockets
diff options
context:
space:
mode:
Diffstat (limited to 'websockets')
-rwxr-xr-xwebsockets/server.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/websockets/server.js b/websockets/server.js
index 6b32cba..d0b963b 100755
--- a/websockets/server.js
+++ b/websockets/server.js
@@ -16,10 +16,11 @@ const server=new WebSocket.Server({port:PORT},()=>{
server.on("connection",(sock)=>{
let netconn=null;
let buffer=[];
+ let linebuf="";
netconn=net.connect(upstream.port,upstream.host,()=>{
for(const item of buffer){
- netconn.write(item);
+ netconn.write(item+"\n");
}
buffer=[];
});
@@ -27,7 +28,12 @@ server.on("connection",(sock)=>{
sock.close();
});
netconn.on("data",(data)=>{
- sock.send(data);
+ linebuf+=data;
+ let idx;
+ while((idx=linebuf.indexOf("\n"))!=-1){
+ sock.send(linebuf.slice(0,idx));
+ linebuf=linebuf.slice(idx+1);
+ }
});
sock.on("close",()=>{
@@ -35,7 +41,7 @@ server.on("connection",(sock)=>{
});
sock.on("message",(data)=>{
if(netconn.connecting)buffer.push(data);
- else netconn.write(data);
+ else netconn.write(data+"\n");
});
});