Code Monkey home page Code Monkey logo

chat-example's Introduction

Socket.IO chat example

This is the source code for a very simple chat example used for the Tutorial guide of the Socket.IO website.

You can run this example directly in your browser on:

chat-example's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chat-example's Issues

the io event with step module

if I using the step module with io.on('connection', function(){
});
it will have some problem, if the socket is lately start than client, the client will not receive other event from the socket server, it on have the connection.
please explain the problem, and how to fix it ?

blank - no texts sent or received

I tried copying and pasting the code and run the application. I checked the: " io.on('connection', function(socket){ " part and it works when a user connects. But the other part of " socket.on..... " doesn't seem to be working. When I enter texts in the form I get blank on the client page and the server is blank as well. I tried to test it by typing console.log to display something when "socket.on" gets fired, but nothing shows up. What's missing? Can anyone please help?

Thanks

Get the request URL in the index.js

I have make a new variable call httpd and named it as var httpd = require('http'); and I use it to create and get the client request file, and now I want to emit a value when someone visit /greet path it will emit to chat room so I add this before io.on code
I add the following code
var httpd = require('http);
var path;
httpd.createServer(function (req, res) {
path = req.url;
};
if (path == "/greet") {
io.on ....

But the code doesn't emit a value to chatroom when someone visit /greet
What I'm missing?
Or we can't get req.url in socket.io code?

Cannot establish polling connection

I'm using Firefox (108.0, MacOS 13.1).
When I run this project, the browser debugger shows there's some 500 responses from the server.
图片
I added this code to the index.js, and the server console logs:

io.engine.on("connection_error", (err) => {
  // console.log(err.req);      // the request object
  console.log(err.code);     // the error code, for example 1
  console.log(err.message);  // the error message, for example "Session ID unknown"
  console.log(err.context);  // some additional error context
});

图片

I guess the problem is: the websocket connection was established successfully, but the polling connection failed.
So I tried to add a parameter to allow only polling:

const io = require('socket.io')(http, {
  transports: ['polling']
});

Then, the connection never establishes successfully. The browser sends requests and gets 500 responses infinitely. The server also gets "Session ID unknown" infinitely.
图片
图片

Looks like a new connection starts to establish when the previous connection hasn't finished establishing.

I've tried the latest version (4.5.4) of "socket.io" and "socket.io-client", the behavior is the same.
And I found the polling connection can be successfully established in the latest version of Chrome, but failed in Edge as in Firefox.

How can I solve this?

Last step missing var socket = io();

Hi, I'm new to NodeJS .. I got to the last step and nothing happened. I looked over the code and noticed it was missing
var socket = io();
like the previous steps had

What package should I get?

i use pacaage
npm i socket.io
npm i express

스크린샷 2020-06-23 오전 11 45 52

I downloaded the package and received a lot of requests like an image.
What package should we apply?
The code is the same as the original code.

form.addEventListener is not a function

I'm getting this error about the form addEventListener and I can't understand why.
I already tried to copy the code and still get the same error.

Uncaught TypeError: form.addEventListener is not a function
at index.js:10:6

`var socket = io();

var input = document.getElementById('input');
var roomInput = document.getElementById('room-input');
var messages = document.getElementById('messages');
var form = document.getElementById('form');

form.addEventListener('submit', function(e) {
e.preventDefault();
if (input.value) {
socket.emit('chat message', input.value);
input.value = '';
}
});

socket.on('chat message', function(msg){
var item = document.createElement('li');
item.textContent = msg;
messages.appendChild(item);
window.scrollTo(0, document.body.scrollHeight);
});`

Can you help me, please?

Regards!
Pedro

Messaging is not working

In this project some i get is
First one is Two user are connected then it's not get alert or any type of other suggestion
Second one is when user click on the send button then the message not send or not show in any place like a nothing to see just realise message was send but which place send it's not see

SO i need some help please

any one do this then tell me i'm still waiting for a good developer

Multiple socket.ids generated

This code is not working alrite....multiple socket.ids generated from the same tab. So sometimes client connects to himself or others connect to non existing client.

page not working on intranet

"Chat" works fine on "localhost", using 3 different browsers but on intranet, page is not"sending" or receiving. tried suggestion on #21 but did not fix

Works, but cannot be connected to using a public IP.

What the title says. I have copied and slightly modified the code. It works as intended, but I can only connect from the machine it is running on (using localhost:3000 or 192.168.1.3:3000). I have attempted to use port forwarding but it did not help the issue. I'd like to know how I can make the app accessible from another machine, and if it is possible to host the app on GH Pages.

Dosent Work Offline

I got the socket js and jquery js file offline and ran my nodemon, but it doesn't work, but works if am using the socket js and jquery js file from cdn

io not defined

index.html, line 26:
var socket = io();

=> 'io' not defined

Cannot run on IE or EDGE

when I download this demo; I can run it on chrome ;but not send message on ie or edge ; always say io is not defined

License

Hi, I'll maybe use this code or snippet from this.

I can't see any license, so for now it means it's closed by default.

Is is free software ?

Microsoft Edge Crushing Nodejs

Great example, however it seems my Microsoft Edge v 123.0.2420.1 is killing the script every time I start typing in Edge.

Edge is receiving other messages from Chrome and Firefox without problem.

C:\Users\ted\NODEDEV\WEBSOCKET3\index.js:46
callback();
^

TypeError: callback is not a function
at Socket. (C:\Users\ted\NODEDEV\WEBSOCKET3\index.js:46:7)

Node.js v18.18.2
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting node index.js
server running at http://localhost:3000

How can I resolve sending messages by Edge?

Old Messages

Messages written before a user opens the page do not appear

Getting started outdated version

I wasted around 2 hours wondering why it's not working when I did everything like in this tutorial:
https://socket.io/get-started/chat/
I downloaded code from github. Copied everything from index.js - not working, everything from index.html - not working. Then I look to package.json - damn, that's some old one. Finally when I copied package.json and reinstalled it started working.

But I can't get it going with newest version because... tutorial is just shi**y, sorry

cros problem

The example has Access-Control-Allow-Origin problem.

I just edit index.html

var socket = io('http://localhost:3000');

Then the Chrome Console print like this

Failed to load http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1521768422803-4: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access.

Sent message doesn't show in the other tab

I followed the tutorial and I test it by opening 2 tabs to connect and it shows both are connected but when I send the message on one tab the other tab is not updated.

Sample app does not work because client socket.io version is hard-coded from a CDN

In this sample app, it hard codes a CDN reference to v1.2 of socket.io. When someone tries to implement this sample app and the current version of socket.io that they are using on their server is no longer 1.2, it does not work and it is difficult to figure out why. I would think the script tag should be <script src="/socket.io/socket.io.js"></script> so that it always loads the right version of the client. For an example of how confused a socket.io newbie gets when this happens see this question/answer on stackoverflow.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.