-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
38 lines (36 loc) · 1.09 KB
/
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
var net=require("net");
/**
* 创建server
*/
function t1(){
var server=net.createServer(function(socket){
//socket.end("good bye!");
socket.write("hello,i'm server!");
console.log("client connected! %j:%j",socket.remoteAddress,socket.remotePort);
socket.on("data",function(data){
console.log("recived from client:",data.toString());
})
socket.on("close",function(had_error){
if(!had_error){
console.log("client closed success! %j:%j",socket.remoteAddress,socket.remotePort);
}
else{
console.log("client close error! %j:%j",socket.remoteAddress,socket.remotePort);
}
})
socket.on("error",function(err){
console.log("!!!err!!!",err);
});
//setTimeout(function(){
// socket.end("我结束了","utf8");
//},3000);
});
server.listen({
port:8811
},function(){
var address=server.address();
console.log(" opened server on address %j ",address);
});
var a=1;
}
t1();