Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Socket server stoping after few second

$
0
0

Hi everyone, I started to use Titanium today so be kind ! hopfully my question will make sense !

I am running the latest version of titanium sdk and ios sdk/sim.

Here is my problem, I need to run a udp socket server with my app which I manage to do using the udp module:

var UDP = require('ti.udp');
 
function Server() {
    var socket = UDP.createSocket();
 
    socket.addEventListener('started', function(e) {
        Ti.API.info('Socket started');
    });
    socket.addEventListener('data', function(message) {
        Ti.API.info(message);
 
        try {
            var msg = JSON.parse(message.stringData.replace(/\\/g, ""));
 
                socket.sendString({
                    port : 5876,
                    data : "Hello, World!"
                });
 
        } catch(err) {
            Ti.API.error('Something went wrong while receiving a broadcast message');
        }
 
        //Ti.API.info(JSON.stringify(msg));
    });
 
    socket.start({
        port : 5877
    });
 
    socket.addEventListener('error', function(e) {
        Ti.API.info('Socket error: ' + e);
    });
 
}
 
module.exports.server = function() {
    Ti.API.info('BroadcastServer is starting');
    var server = new Server();
 
};
when I start the app, the socket server start without any problem but then after it would stop on it's after 5 to 30 seconds and the terminal will show a :

[INFO] : Stopped!

When the server is up I can send and receive message normally.

Thanks for the help !

JB.


Viewing all articles
Browse latest Browse all 8068

Trending Articles