消息不发送发出socket.io + codeigniter

I'm new user in socket.io. I try to make realtime chat with php framework codeigniter + socket.io, i try following instruction at socket.io but i experiencing constraints related to data transmission, data not sent to client and browser reload again...

this my code

server : server.js

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

http.listen(3000, function(){
  console.log('listening on *:3000');
});

var chat = io.of('/chat');
io.on('connection',function(socket){
    socket.on('newMessage', function (msg) {
        io.emit('newMessage', msg);
        console.log('Chat baru: ' + msg);
    });

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

client : chat.php

<div class="row-fluid">
    <!-- block -->
    <div class="block">
      <div class="navbar navbar-inner block-header">
          <div class="muted pull-left">Pesan Masuk</div>

      </div>
      <div class="block-content collapse in">
        <div class="span12">
             <div class="msg_box" id="msg_box">
                <div class="frame_msg">
                    <ul class="ul_list">
                    <!-- <h5 name="msg_name">Indra :</h5><p>coba</p>
                 -->
                    </ul>

                 </div>
             </div>

                    <form action="">
                        <div class="block_send">
                            <textarea type="text" id="message" name="message" class="message"></textarea>
                            <button class="btn btn-primary btn-sm btn_submit message_submit" id="message_submit" onclick="test()"></button>  
                        </div>
                    </form>

        </div>
    </div>
    <!-- end /block -->
  </div>
</div>

<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script src="<?php echo base_url();?>/assets/app/site_url.js" ></script>
<script type="text/javascript">
$(function () {
    var socket = io.connect('http://localhost:3000');
var chat = socket.of('/chat');

$('form').submit(function(){
    chat.emit('newMessage',$('#message').val());
    $('#message').val('');
    return false;
});

chat.on('newMessage',function(msg){ 
    $('.ul_list').append('<h5 name="msg_name">Indra :</h5><p>'+msg+'</p>');
}); 
});

</script>

anyone can help me? thank you very much.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐