websocket.onopen - This method gets executed when a connection between the client and the server is created.
websocket.onclose - This method gets executed when a connection is closed.
websocket.onmessage - This method gets executed when a message is received from server.
websocket.onerror - This will be called if an unhandled error is thrown in above methods.
Below HTML page contains a sample code.
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var ws;
function loadWebsocket() {
if (window.WebSocket) {
//The browser supports WebSockets");
// Open a web socket
ws = new WebSocket("ws://localhost:8080/WebsocketServer1/chat");
ws.onopen = function() {
console.log("Connection is opened...");
};
ws.onmessage = function (evt) {
var message = evt.data;
console.log("Message is received...:" + message);
};
ws.onclose = function() {
console.log("Connection is closed...");
};
ws.onerror = function() {
console.log("Error occured...");
};
window.onbeforeunload = function(event) {
socket.close();
};
} else {
// The browser doesn't support WebSocket
console.log("Your browser doesn't support WebSockets!");
}
}
function sendMessage() {
ws.send("Hello server!");
}
loadWebsocket();
</script>
</head>
<body>
<div id="sse">
<a href="javascript:sendMessage()">Send message</a>
</div>
</body>
</html>
<html>
<head>
<script type="text/javascript">
var ws;
function loadWebsocket() {
if (window.WebSocket) {
//The browser supports WebSockets");
// Open a web socket
ws = new WebSocket("ws://localhost:8080/WebsocketServer1/chat");
ws.onopen = function() {
console.log("Connection is opened...");
};
ws.onmessage = function (evt) {
var message = evt.data;
console.log("Message is received...:" + message);
};
ws.onclose = function() {
console.log("Connection is closed...");
};
ws.onerror = function() {
console.log("Error occured...");
};
window.onbeforeunload = function(event) {
socket.close();
};
} else {
// The browser doesn't support WebSocket
console.log("Your browser doesn't support WebSockets!");
}
}
function sendMessage() {
ws.send("Hello server!");
}
loadWebsocket();
</script>
</head>
<body>
<div id="sse">
<a href="javascript:sendMessage()">Send message</a>
</div>
</body>
</html>
I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.
ReplyDeletefull stack developer training in chennai
Vulpith being the best freelance jobs website online platform, We offers both information security as well as escrow protection and we observed major challenges in working virtually or remotely.
ReplyDeletevisit:
https://vulpith.com/
This comment has been removed by the author.
ReplyDeleteI love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .
ReplyDeleteClick here:
python training in chennai
Click here:
python training in tambaram
Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
ReplyDeleteBlueprism training in Chennai
Blueprism training in Bangalore
Blueprism training in Pune
Blueprism online training
Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
ReplyDeleteData Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.
ReplyDeleteangularjs Training in bangalore
angularjs Training in btm
angularjs Training in electronic-city
angularjs online Training
angularjs Training in marathahalli
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeletepython training in pune | python training institute in chennai | python training in Bangalore
ReplyDeleteHello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
Best AWS Training in Chennai | Amazon Web Services Training in Chennai
AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR
AWS Training in Chennai |Best Amazon Web Services Training in Chennai
AWS Training in Velachery | Best AWS Course in Velachery,Chennai
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training
This comment has been removed by the author.
ReplyDeleteI am really thankful for posting such useful information. It really made me understand lot of important concepts in the topic. Keep up the good work!
ReplyDeleteOracle Training in Chennai | Oracle Course in Chennai
Appreciating the persistence you put into your blog and detailed information you provide.
ReplyDeleteData science training in chennai |Data science course in chennai
nice post...!
ReplyDeleteinternship in chennai for ece students
internships in chennai for cse students 2019
Inplant training in chennai
internship for eee students
free internship in chennai
eee internship in chennai
internship for ece students in chennai
inplant training in bangalore for cse
inplant training in bangalore
ccna training in chennai
this is gud...
ReplyDeletechile web hosting
colombia web hosting
croatia web hosting
cyprus web hosting
bahrain web hosting
india web hosting
iran web hosting
kazakhstan web hosting
korea web hosting
moldova web hosting
Hello there. This blog is awesome! Very informative. Thank you for sharing.
ReplyDeleteAndroid Training Institute in Chennai | Android Training Institute in anna nagar | Android Training Institute in omr | Android Training Institute in porur | Android Training Institute in tambaram | Android Training Institute in velachery
Nice blog,I understood the topic very clearly,And want to study more like this.thans a lot guys.
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
very useful article.Technical contents are so good.Keep going. Java training in Chennai | Certification | Online Course Training | Java training in Bangalore | Certification | Online Course Training | Java training in Hyderabad | Certification | Online Course Training | Java training in Coimbatore | Certification | Online Course Training | Java training in Online | Certification | Online Course Training
ReplyDeleteHere is the site(bcomexamresult.in) where you get all Bcom Exam Results. This site helps to clear your all query.
ReplyDeleteBA 3rd year Result 2019-20
Kerala University B.Com 6th Sem Result 2020
I think you did an awesome job explaining it. Sure beats having to research it on my own. Thanks
ReplyDeleteuniraj ba 3rd year result
Shekhawati University ba final result
Great post. Thanks for sharing your brain. Check mine out sometime. See Season 2 Full Tv Series
ReplyDeleteSex Education Season 3 Download
very useful article.Technical contents are so good.Keep going
ReplyDeleteEscort Service in Noida
Very useful article.Technical contents are so good.Keep going
ReplyDeleteEscort Services in Gurgaon
hey this is amazing article post. thanks for sharing a valuable post. You can visit here for search engine marketing agency in Delhi and why shoyld you hire an seo company in delhi.
ReplyDeleteImpressive! I finally found a great post here. Good article on Data Science. It is really a great experience to read your post. Thank you for sharing your innovative ideas with Our Vision.
ReplyDeleteonline flower shop
orchid wedding bouquet
sunflower wedding bouquet
Wedding Flower Delivery
wedding flowers near me
orchid wedding bouquet
cheap wedding flowers
wedding bouquet flowers online
wedding flowers order online
wedding bouquets near me
flower delivery Dublin
flower delivery Dublin Ireland
flower delivery Dublin
flower delivery Dublin
birthday flowers delivery Dublin
same day birthday flower delivery
flower shop Dublin
birthday bouquet delivery Ireland
send birthday flowers online Ireland
same day birthday flower delivery Ireland
next day birthday flower delivery Ireland
birthday flowers delivery Ireland
Send Birthday Flowers Ireland
order birthday flowers online Ireland
Birthday Flowers Ireland
birthday flowers delivery near me
ReplyDeleteNice blog! Thanks for sharing this valuable information
German Classes in Bangalore
German Language Course in Hyderabad
සුපිරියි බ්ලොග් එක..තව අලුතෙන් පෝස්ට්ස් දාන්න
ReplyDeletekralbet
ReplyDeletebetpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
betmatik
PHR1
شركة تسليك مجاري بالجبيل WZ1vl2rp3M
ReplyDelete