2021-06-27 02:34:43 +03:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
|
|
export default class Counter extends React.Component {
|
|
|
|
|
state = {
|
|
|
|
|
count: 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
increment = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
count: (this.state.count + 1)
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-27 02:45:29 +03:00
|
|
|
startConnection = () => {
|
|
|
|
|
const ws = new WebSocket("ws://localhost:5000");
|
|
|
|
|
ws.onopen = (event : Event)=>{
|
|
|
|
|
console.log("onopen");
|
|
|
|
|
ws.send("Messgage from client");
|
|
|
|
|
}
|
|
|
|
|
ws.onmessage = (event : MessageEvent) =>{
|
|
|
|
|
console.log(event.data);
|
|
|
|
|
}
|
2021-06-27 02:34:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<h1>{this.state.count}</h1>
|
2021-06-27 02:45:29 +03:00
|
|
|
<button onClick={this.startConnection}>Start Connection</button>
|
2021-06-27 02:34:43 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|