1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Socket for 2 devices on same network not working

Discussão em 'Angular' iniciado por Thomas G, Setembro 10, 2024.

  1. Thomas G

    Thomas G Guest

    I'm actually working on an ElectronJS Application and an Ionic App.

    The Electron app has a Socket server (using SockJS) and the Ionic app the Socket client.

    My problem is when i launch the two app on the same device, it's working fine, but, when the Electron App is launch on my computer and the Ionic app on my android device, it's not working.

    I tried with my local IP, localhost, 0.0.0.0, 127.0.0.1. But no one works.

    Electron :

    const {ipcMain} = require('electron')
    let app = require('express')();
    const http = require('http').Server(app);
    let io = require('socket.io')(http);

    io.sockets.on('connection', function (socket) {
    console.log('socket connected');

    socket.on('disconnect', function () {
    console.log('socket disconnected');
    });

    socket.emit('text', 'wow. such event. very real time.');
    });

    var port = process.env.PORT || 9999;

    http.listen(port, function(){
    console.log('listening in http://localhost:' + port);
    });


    Ionic :

    import { Injectable } from '@angular/core';
    import { HttpClient } from '@angular/common/http';
    import { Socket, SocketIoConfig } from 'ngx-socket-io';

    @Injectable({
    providedIn: 'root'
    })
    export class CoreService {
    config: SocketIoConfig
    private socket: Socket
    constructor(private http:HttpClient) {
    this.config = { url: 'http://localhost:9999', options: { secure: true } };
    }

    connectSocket() {
    this.socket = new Socket(this.config)
    this.socket.connect()
    this.socket.on('text',(value) => {
    console.log(value)
    })
    }
    }


    If anyone can help me.

    EDIT 1

    I try much things. I have desactivate my firewall for testing and try this IP (Localhost, 0.0.0.0, local IP, 127.0.0.1) but no one works.

    The communication works when i'm in the same computer (Ionic on emulator or web browser). But when i'm testing in my android device, it's not working. (I'm on the same network)

    I have no error on ionic :

    D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
    W/InputMethodManager: startInputReason = 1
    I/HwSecImmHelper: mSecurityInputMethodService is null
    I/HwSecImmHelper: mSecurityInputMethodService is null
    I/HwSecImmHelper: mSecurityInputMethodService is null
    I/HwSecImmHelper: mSecurityInputMethodService is null
    I/HwSecImmHelper: mSecurityInputMethodService is null
    I/HwSecImmHelper: mSecurityInputMethodService is null


    And i'm now using Socket.io instead of SockJS, but still not working..

    Continue reading...

Compartilhe esta Página