Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
Socket IO Generación de conexiones múltiples

Estoy usando socket-io para hacer una aplicación de entrega, pero no sé por qué me genera dos conexiones, si solo tengo un teléfono celular conectado, ¿alguien puede ayudarme con eso?

Necesito exportar el io para hacer emit y otras cosas en las rutas de peticiones, tipo de cuando se crea un nuevo pedido, o se acepta un pedido.

Mi código socketio.js es este

 import { Server as WebSocketServer } from "socket.io"; import http from "http"; import app from "../app"; const httpServer = http.createServer(app); const io = new WebSocketServer(httpServer); export { httpServer, io, }

Mi índice js es este.

 import { httpServer, io } from "./middlewares/socketio"; import "./database"; require("dotenv").config(); var admin = require("firebase-admin"); var serviceAccount = require("./deliveram-test-firebase-adminsdk-vqinw-368ea4a624.json"); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), }); io.on("connection", function (socket) { console.log("New Connection: ", socket.id); }); httpServer.listen(process.env.PORT || 3000, () => { console.log("Server is running on port: " + process.env.PORT || 3000); }); 

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Estoy usando este contexto para gestionar las peticiones.

 import React, {createContext, useState, useContext, useEffect} from 'react'; import {showError} from '../utils/helperFunctions'; import {io} from 'socket.io-client'; import {API_URL} from '../config/urls'; const socket = io(API_URL); const SocketContext = createContext(); const SocketProvider = ({children}) => { const [newOrder, setNewOrder] = useState(); const [deleteOrder, setDeleteOrder] = useState(); const [newUbication, setNewUbication] = useState(); const [orderUpdated, setOrderUpdated] = useState(); const [orderAccepted, setOrderAccepted] = useState(); const [socketId, setSocketId] = useState(); socket.on('connect', () => { setSocketId(socket.id); }); socket.on('orderSaved', data => { setNewOrder(data ? data : null); }); socket.on('orderDeleted', data => { setDeleteOrder(data ? data : null); }); socket.on('updateUbication', data => { setNewUbication(data ? data : null); }); socket.on('orderAccepted', data => { setOrderAccepted(data ? data : null); }); return ( //This component will be used to encapsulate the whole App, //so all components will have access to the Context <SocketContext.Provider value={{ newOrder, deleteOrder, newUbication, orderAccepted, socketId, }}> {children} </SocketContext.Provider> ); }; //A simple hooks to facilitate the access to the AuthContext // and permit components to subscribe to AuthContext updates function useSocketIO() { const context = useContext(SocketContext); if (!context) { throw new Error('useSocketIO must be used within an SocketProvider'); } return context; } export {useSocketIO, SocketContext, SocketProvider};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!