I have made J2ME application for sending and receiving SMS in which message listener is used for listening Incoming message from particular port number.
I want to make SMS Receiver which listen all incoming SMS from anywhere instead from particular port(when I open message connection it ask for port number).
How to implement this??
If possible suggest some source code.
Hope to hear from you soon.
Current code:
msgConnection = (MessageConnection)Connector.open("sms://:" + port);
msgConnection.setMessageListener(listener);
void notifyIncomingMessage(MessageConnection conn) {
Message message;
try {
message = conn.receive();
}
}
Regards,
Parmanand
Related
I am sending message from server by the client.send method and in postman i want to get all messages without adding any event listener like web socket.
In web socket, we do not need to add any event listener,
Similarly, In the socket.io, I want to get all messages without listening to message event like web socket.
server
const socketClients = await this.io.fetchSockets();
socketClients.forEach((client: any) => {
client.send(JSON.stringify(obj))
}
This code sends message to the client, when I am adding an event listener to the postman, getting all messages but I want to get messages without adding event listener like web socket.
I hope you understand my question,
hoping a good answer by you,
Thanks.
I'm running a chat server using node.js and socket and want to send message to specific client.I use socket.id to send the message to the defined user,like this:
io.sockets.in(user socket.id).emit('message',message)
but there is a problem:
user remains connect but socket id changes rapidly(About once per second) so i can not use socket.id.I tried socket.join(user email) to use user email instead of socket id but after socket id changes it does not work any more.
what's the best way to solve this?session-id?If yes,how?chat application for clients runs on android device.
This is my code:
io.on("connection", function(socket) {
socket.on("login", function(useremail) {
socket.join(useremail);
});
//Here i want to send message to specific user
socket.on('messagedetection', (senderNickname,messageContent,targetuser) => {
//create a message object
let message = {"message":messageContent, "senderNickname":senderNickname}
//targetuser is the email of target user,joined to the socket in login
io.sockets.in(targetuser).emit('message',message)
});
socket.on('disconnect', function() {
console.log( ' user has left ')
socket.broadcast.emit("userdisconnect"," user has left ") });
Making my comment into an answer since it was indeed the issue:
The problem to fix is the rapidly disconnecting/reconnecting clients. That is a clear sign that something in the configuration is not correct.
It could be that network infrastructure is not properly configured to allow long lasting socket.io/webSocket connections. Or, if your system is clustered, it could be caused by non-sticky load balancing.
So, each time the connection is shut-down by the network infrastructure, the client-side socket.io library tries to reconnect creating a new ID for the new connection.
I want to create an Event Publisher that connect via Websocket. When I try to connect it with my simple socket io server, the url is
ws://localhost:3000/socket.io/
It didn't receive the stream..
I've set the inline format for the stream like this :
42["input-message",{"LAT":{{latitude}},"LON":{{longitude}}}]
If I understand your question correctly,
you do not get any errors when the event is published from the CEP
server
but the socket io server does not show any indication that it
received the event either.
CEP server showing no error logs means:
CEP server is successfully connected to the socket io server. (if the connection is dropped, then you should see an error log, and CEP will try to reconnect)
Probably the event was sent to socket io server by Websocket publisher (or the Websocket publisher did not recieve any event at all to be sent to socket io server)
(When you send an event, if the CEP server cannot parse the event, then also you should see an error log.)
Here are some points which might help you to troubleshoot the issue:
Enable tracing in your websocket publisher (You may refer to this 'Event Tracer' doc). Then send an event and check the traces. This will allow you to verify whether the Websocket publisher recieved the event.
If there are traces shown for the publisher, but still no event received at the socket io server, then it could be that some error occurs at socket io server, and the exception is not logged (might have being swallowed).
Hope this will help.
Because I cannot directly connect to the socket.io, thus I created a simple websocket that act as a middleware that sending the input from WSO2CEP into the socket.io
var io = require('socket.io').listen(server);
io.set('origins', '*:*');
var WebSocketServer = require('ws').Server,
wss = new WebSocketServer({ port: 8087 })
//wss sending every message that it received to the socket.io
wss.on('connection', function connection(ws) {
console.log('a WSO2CEP-PUBLISHER is connected');
ws.on('message', function incoming(message) {
console.log('received: %s', message);
io.emit('input-message', JSON.parse(message));
});
});
notice that, the data that come from event publisher is string formatted, so if needed to send it as a JSON object, than use JSON.parse() function.
In a chat service that I'm building, I need to send messages directly from the server.
I have found no solution, there is an example in the documentation:
// SERVER
io.sockets.on('connection', function (socket) {
socket.on('ferret', function (name, fn) {
fn('woot');
});
});
// CLIENT
socket.on('connect', function () { // TIP: you can avoid listening on `connect` and listen on events directly too!
socket.emit('ferret', 'tobi', function (data) {
console.log(data); // data will be 'woot'
});
});
but does the opposite of what I need!
I need to do the emit from the server and receive a confirmation of receipt from the client!
Is there a way to do this?
there is no guarantee as the connection can be killed before the servers message reaches the client. thus there is also no event on the server like "clientGotMessage". if a message MUST reach the user there is no other way than to tell the server that you received the message on the client.
You can do this 'easy' by sending a number down. client and server keep track of that number. each time the server sends, it counts up, each time the client receives, it counts up. When the client sends something, it sends the number, so the server will see if the client has everything. If the client missed a message, the next message will have a number that the client wont accept and request the lost message from the server.
I am able to send the message to particular namespace room with the following code
io.of(namespace).in(room).emit('functionname', data);
but it sending to all the connected client including the sender, what I want is I want to send the message excluding the sender, I have tried with following method but everything failed since syntax is not correct
io.broadcast.of(namespace).in(room).emit('functionname', data);
io.of(namespace).broadcast.in(room).emit('functionname', data);
io.of(namespace).in(room).broadcast.emit('functionname', data);
io.of(namespace).in(room).broadcast('functionname', data);
How can I send the message to every client excluding the sender.
I believe what you want is along the lines of this:
// send to all clients except sender
socket.broadcast.emit('event', "this is a test");
// send to all clients in 'room' room except sender
socket.broadcast.to('room').emit('event', 'whadup');
// sending to all clients in 'room' room, include sender
io.sockets.in('room').emit('event', 'woodup');
You can add the "of.(namespace)" if you wish to specify the namespace as well.
Do this to send a message to everyone except the sender:
socket.broadcast.emit('event', "this is a test");
i have got that problem. io.of() confused me.
when you used 'connection' as io.of(),
your socket already got namespace. so you just add particular room.
io.of(namespace).in(room).emit('functionname', data);
-> sokcet.broadcast.emit('event',data);
I was having trouble with this too.
The key is to use
socket and not io
This will NOT work:
io.of(namespace).broadcast.to(room).emit('event', data)
However, this will work:
socket.to(room).emit('event', data)
One drawback though is that this will only work if the socket you are sending from is in the namespace you want to send to. If you want to send to a different namespace, I don't think this approach would work