tested websocket

This commit is contained in:
jhalitaksoy 2021-06-27 02:45:29 +03:00
parent 76d54207f0
commit 19d1d8982b

View File

@ -11,18 +11,22 @@ export default class Counter extends React.Component {
}); });
}; };
decrement = () => { startConnection = () => {
this.setState({ const ws = new WebSocket("ws://localhost:5000");
count: (this.state.count - 1) ws.onopen = (event : Event)=>{
}); console.log("onopen");
ws.send("Messgage from client");
}
ws.onmessage = (event : MessageEvent) =>{
console.log(event.data);
}
}; };
render () { render () {
return ( return (
<div> <div>
<h1>{this.state.count}</h1> <h1>{this.state.count}</h1>
<button onClick={this.increment}>Increment</button> <button onClick={this.startConnection}>Start Connection</button>
<button onClick={this.decrement}>Decrement</button>
</div> </div>
); );
} }