Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Converting circular structure to JSON #1101

Closed
kpachbiu88 opened this issue Dec 4, 2012 · 3 comments
Closed

Uncaught TypeError: Converting circular structure to JSON #1101

kpachbiu88 opened this issue Dec 4, 2012 · 3 comments

Comments

@kpachbiu88
Copy link

Client (browser Chrome latest version):
Connect to server, pull out the plug online, wait 2 minutes, plug connect the Internet again.

Trigger events: disconnect, then reconnect.

The client when receiving data see error message in the console
Uncaught TypeError: Converting circular structure to JSON
and no data is being received.

From client to server data is transferred perfectly

Problems arise only when the client is lost internet connection. If the client does not reconnect no problem.

I see the error in your socket.io library.
Write how you can solve the problem?

Client Code (browser Chrome latest version):
var socket = io.connect('http://consultant.laura.ru:1988');

socket.on('disconnect', function () {
socket.client = client;
socket.emit('client_disconnect', socket);
console.log('Клиент '+client.client_id+' отключен');
});

socket.on('sendMessage', function (data) {
var audio = $("._quty_chat #c_sound")[0];
audio.play();
setMessage(data);
});

$('._quty_chat .c_send').click(function(){
var msg = $('._quty_chat .c_write input').val();

    if (msg.length > 0) {
        var message = {
            dialog_id: dialog_id,
            client_id: client.client_id,
            user_id: consultant_id,
            text: msg,
            path: 1,
            name: client.name
        };

        socket.emit('sendMessage', message);
        setMessage(message);
            $('._quty_chat .c_write input').val('');
    } else {
        alert('Введите текст сообщения');
    }

        return false;

});

Server code (NodeJS last version):

var io = require('socket.io').listen(1988);
io.set('log level', 1);
io.set('transports', ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling']);

var operators = []; //Операторы онлайн
var clients = []; //Клиенты онлайн

io.sockets.on('connection', function (socket) {
socket.on('reconnect_client', function (data) {
socket.client = data;
clients[data.client_id] = socket;

    console.log(socket.client);
    console.log('Клиент '+data.client_id+' переподключен');
});

socket.on('sendMessage', function(data){
    var con = mysql_connect();
    con.query("INSERT INTO messages VALUES ('', '"+data.dialog_id+"', '"+data.user_id+"', '"+data.client_id+"',  NOW(), '"+data.text+"', '"+data.path+"')",
        function(err, res, fields){
            if (err) {
                console.log(err);
            }

            if (data.path == 0) { //Отправляем сообщение клиенту
                var socket_client = clients[data.client_id];
                if (typeof(socket_client) != 'undefined') {
                    socket_client.emit('sendMessage', data);
                    console.log('Сообщение клиенту отправлено успешно');
                } else {
                    console.log(clients[data.client_id]);
                    //console.log(clients);
                    console.log('Клиент '+data.client_id+' не найден');
                    //console.log(clients);
                }
            } else { //Отправляем сообщение оператору
                var socket_user = operators[data.user_id];
                if (typeof(socket_user) != 'undefined') {
                    socket_user.emit('sendMessage', data);
                    console.log('Сообщение оператору отправлено успешно');
                } else {
                    console.log('Оператор '+data.user_id+' не найден');
                }
            }
    });
});

});

@kpachbiu88
Copy link
Author

http://s018.radikal.ru/i520/1212/98/ffd656a23f79.jpg
Error on line number 1066 file socket.io.js (client)

@kpachbiu88
Copy link
Author

Why this error after reconnect ?

@kpachbiu88
Copy link
Author

I find solution!
I'am stupid guy 👎

Logic error in client code:

client = {
id: 123,
name: 'Petr'
};

socket.on('disconnect', function () {
socket.emit('client_disconnect', client);
});

You may want to do the processing of coding errors.

Thanks for Socket.IO 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants