-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c90b6b
commit 4db7b70
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as nodeDataChannel from '../../lib/index.js'; | ||
|
||
const clientSocket = new nodeDataChannel.WebSocket(); | ||
|
||
clientSocket.open('ws://127.0.0.1:3000'); | ||
|
||
clientSocket.onOpen(() => { | ||
console.log('Client socket opened'); | ||
clientSocket.sendMessage('Echo this!'); | ||
}); | ||
|
||
clientSocket.onMessage((message) => { | ||
console.log('Message from server: ' + message); | ||
}); | ||
|
||
clientSocket.onClosed(() => { | ||
console.log('Client socket closed'); | ||
}); | ||
|
||
// clientSocket.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as nodeDataChannel from '../../lib/index.js'; | ||
|
||
const ws = new nodeDataChannel.WebSocketServer({ bindAddress: '127.0.0.1', port: 3000 }); | ||
|
||
ws.onClient((clientSocket) => { | ||
clientSocket.onOpen(() => { | ||
console.log('Client socket opened'); | ||
clientSocket.sendMessage('Hello from server'); | ||
}); | ||
|
||
clientSocket.onMessage((message) => { | ||
console.log('Message from client: ' + message); | ||
clientSocket.sendMessage(message); | ||
}); | ||
|
||
clientSocket.onClosed(() => { | ||
console.log('Client socket closed'); | ||
}); | ||
}); | ||
|
||
// When done, close the server | ||
// ws.stop(); |