Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:23:31+00:00 2026-06-14T03:23:31+00:00

The client and server connect just fine. For some reason the emit on my

  • 0

The client and server connect just fine. For some reason the emit on my client is not firing correctly. I am trying to get the testEmit and testEmit2 working.

This is my server:

express = require 'express'
mongo = require 'mongodb'
app = express()
server = (require 'http').createServer(app)
io = (require 'socket.io').listen(server)

server.listen(8080)

app.use(express.static(__dirname + '/public'))

# db = new mongo.Db("documentsdb", new mongo.Server("localhost", 27017, auto_reconnect: true), {safe:true})

io.sockets.on 'connection', (socket) ->
    console.log 'Socket.io is connected!'
    #This returns an array of documents sorted via date by decreasing order. (Most recent documents first.)
    socket.on 'loadRecentDocuments', ->
        console.log 'Loading most recent documents.'
        db.collection 'documents', (err, collection) ->
            collection.find().sort(dateAdded: -1).toArray (err, documents) ->
                #This emit is recieved at index.html where a javascript function sendDocuments manages the documents.
                socket.emit 'sendDocuments', documents
                return

    #The index.html provides the code data from the search box via a javascript.
    io.sockets.on 'findDocuments', (code) ->
        #Returns an array of documents with the corresponding class code.
        documentCodeToSearch = code
        console.log 'Retreaving documents with code: ' + documentCodeToSearch
        db.collection 'documents', (err, collection) ->
            collection.find(code:documentCodeToSearch).toArray (err, documents) ->
                socket.emit 'sendDocuments', documents
                return

    #Uploads a document to the server. documentData is sent via javascript from submit.html
    io.sockets.on 'addDocument', (documentData) ->
        console.log 'Adding document: ' + documentData
        db.collection 'documents', (err, collection) ->
            collection.insert documentData, safe: true
            return

    #Test socket.io
    io.sockets.on 'testEmit', ->
        console.log('Emit recieved.')
        socket.emit 'testEmit2', 'caca'
        return

app.listen 1337
console.log "Listening on port 1337..."

This is my client:

<!doctype HTML>
<html>
<head>
    <title>ProjectShare</title>
    <script src="http://localhost:8080/socket.io/socket.io.js"></script>
    <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script>
        //Make sure DOM is ready before mucking around.
        $(document).ready(function()
        {
            console.log('jQuery entered!');
            var socket = io.connect('http://localhost:8080');   
            socket.emit('testEmit');
            socket.on('testEmit2', function(data)
            {
                console.log('Emit recieved at browser.');
                console.log(data);
            });
            console.log('jQuery exit.');
        });
    </script>
</head>
<body>
    <ol>
        <li><a href="index.html">ProjectShare</a></li>
        <li><a href="guidelines.html">Guidelines</a></li>
        <li><a href="upload.html">Upload</a></li>
        <li>
            <form>
                <input type = "search" placeholder = "enter class code"/>
                <input type = "submit" value = "Go"/>
            </form>
        </li>
    </ol>
    <ol id = "documentList">
    </ol>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:23:32+00:00Added an answer on June 14, 2026 at 3:23 am

    Try changing io.sockets to socket on

    io.sockets.on 'findDocuments', (code) ->
    

    &&

     io.sockets.on 'testEmit', ->
    

    That should do the trick

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not able to connect a simple client and a simple server. When I
I am trying to connect to a standalone desktop tcp server(java) from tcp client
I'm trying to create a PHP client to connect to a simple java server,
Simple scenario: Client connects to server with socket.io ( socket = io.connect(...) ) Server
The following is the setup: Server Client | | accept connect | | v
I've got a client app which has to connect to a server and register
I have a .NET client that needs to connect to a remote SQL Server
I've built apps that connect to a server. But this time a client has
My TCP server is implemented using Netty. My client using vanilla java.net.Socket to connect
I am trying to write a very simple unix domain datagram client/server. Here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.