Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Cap32 committed Nov 11, 2017
1 parent 7631666 commit 54f2da2
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ import { Server, Client } from 'promise-ws';
(async function main() {
const port = 3000;
const server = await Server.create({ port });
const client = await Client.create(`ws://127.0.0.1:${port}`);
server.reply('say', async (data) => {
console.log('data'); /* 'hello' */
return 'world';
});
const response = await client.request('say', 'hello');
console.log(response); /* 'world' */

const url = `ws://127.0.0.1:${port}`;
await Client.autoReconnect(url, async (client) => {
const response = await client.request('say', 'hello');
console.log(response); /* 'world' */
});
}());
```

Expand Down Expand Up @@ -224,9 +227,9 @@ import { Client } from 'promise-ws';
const url = 'ws://127.0.0.1:3000';
const res = await Client.connect(url, async (client) => {
/* do something... */
return 'response data';
return 'chris';
});
console.log('res', res); /* will be 'response data' */
console.log('res:', res); /* res: chris' */
}
catch (err) {
if (err.message === 'CLOSE') { console.error('server closed'); }
Expand Down Expand Up @@ -260,9 +263,9 @@ import { Client } from 'promise-ws';
const url = 'ws://127.0.0.1:3000';
const res = await Client.autoReconnect(url, async (client) => {
/* do something... */
return 'response data';
return 'chris';
});
console.log('res', res); /* will be 'response data' */
console.log('res:', res); /* res: chris' */
}
catch (err) {
console.error(err);
Expand Down

0 comments on commit 54f2da2

Please sign in to comment.