Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to send message to server ?? #37

Open
cuongphuong opened this issue Aug 20, 2018 · 6 comments
Open

how to send message to server ?? #37

cuongphuong opened this issue Aug 20, 2018 · 6 comments

Comments

@cuongphuong
Copy link

cuongphuong commented Aug 20, 2018

sendMessage(message){ this.refWebSocket.sendMessage(message); } is not working
help me!! please!

@mehmetbektas
Copy link
Contributor

mehmetbektas commented Aug 27, 2018

Hi, @cuongphuong
Did you set refWebSocket attribute, like as

ref={Websocket => {
this.refWebSocket = Websocket;
}}

I have succed to send message in this example:
https://github.com/mehmetkose/react-websocket/blob/master/example/component.jsx

@harry91
Copy link

harry91 commented Sep 4, 2018

the same problem, not working...

@jonathan-chin
Copy link

@mehmetbektas 's solution worked for me.

@masood1
Copy link

masood1 commented Dec 5, 2019

Hey make sure you use JSON.stringify() to "message" object if it is not a string,

Here is my example project, you can use this repo too
https://github.com/masood1/SensorManagement

@kunambi
Copy link

kunambi commented Aug 19, 2020

@mehmetbektas's solution works, but you may have to change it slightly to: this.websocketRef.current.sendMessage(myString) (added current)

@exaucae
Copy link

exaucae commented Oct 31, 2021

can someone close this issue since its resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants