我正在尝试在连接时向客户端发送数据包。 对于服务器端,我使用了Socket.io和OSGI以及Karaf。 我正在发送
server.addConnectListener(new ConnectListener(){
@Override
public void onConnect(SocketIOClient client) {
log.info("A new client has connected -> {}", client.getSessionId());
int count = 1;
boolean count1 = true;
StringBuffer builder = new StringBuffer();
for(int i=0; i < 5; i++) { builder.append("A"); }
Packet packet = new Packet(PacketType.EVENT);
packet.setName("trader");
ArrayList arr = new ArrayList();
arr.add(builder.toString());
packet.setData(arr);
System.out.println("sending data " + arr);
client.send(packet);
}
});
和我正在访问的客户端
<script src='http://code.jquery.com/jquery-1.7.2.min.js'></script>
<script src='https://cdn.socket.io/socket.io-1.1.0.js'></script>
<script>
var socket = io.connect('ws://localhost:8807');
socket.on('connect', function(data) {
debugger;
console.log("connected");
});
socket.on('time', function(data) {
console.log(data);
$('#messages').append('<li>' + data.time + '</li>');
});
socket.on('trader', function(data){
console.log("recieving data");
$('#messages').append('<li>' + data + '</li>');
});
socket.on('Message', function(data){
console.log("recieving data");
$('#messages').append('<li>' + data + '</li>');
});
socket.on('error', function(data) {
debugger;
console.error(arguments)
});
</script>
我收到的错误是 消息:&#34; xhr轮询错误&#34;,输入:type:&#34; TransportError&#34;