Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18246] socket isWriteable method is undefined

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsdefect, ios
ReporterDavid He
AssigneeUnknown
Created2014-12-16T00:37:53.000+0000
Updated2018-02-28T19:55:19.000+0000

Description

Run the test code as follow will reproduce this error.
var hostname = '127.0.0.1';

var clientSocket = Ti.Network.Socket.createTCP({
	host : hostname,
	port : 40404,
	connected : function(e) {
		Ti.API.info('Client socket connected!');
		Ti.Stream.pump(e.socket, pumpCallback, 1024, true);
		e.socket.write(Ti.createBuffer({
			value : 'A message from a connecting socket.'
		}));
	},
	error : function(e) {
		Ti.API.info('Error (' + e.errorCode + '): ' + e.error);
	}
});

function writeCallback(e) {
	Ti.API.info('Successfully wrote to socket.');
}

function pumpCallback(e) {
	// Has the remote socket closed its end?
	if (e.bytesProcessed < 0) {
		Ti.API.info("Closing client socket.");
		clientSocket.close();
		return;
	}
	try {
		if (e.buffer) {
			var received = e.buffer.toString();
			Ti.API.info('Received: ' + received);
		} else {
			Ti.API.error('Error: read callback called with no buffer!');
		}
	} catch (ex) {
		Ti.API.error(ex);
	}
}

//Create a socket and listen for incoming connections
var listenSocket = Ti.Network.Socket.createTCP({
	host : hostname,
	port : 40404,
	accepted : function(e) {
		// This where you would usually store the newly-connected socket, e.inbound
		// so it can be used for read / write operations elsewhere in the app.
		// In this case, we simply send a message then close the socket.
		Ti.API.info("Listening socket <" + e.socket + "> accepted incoming connection <" + e.inbound + ">");
		e.inbound.write(Ti.createBuffer({
			value : 'You have been connected to a listening socket.\r\n'
		}));
		e.inbound.close();
		// close the accepted socket

	},
	error : function(e) {
		Ti.API.error("Socket <" + e.socket + "> encountered error when listening");
		Ti.API.error(" error code <" + e.errorCode + ">");
		Ti.API.error(" error description <" + e.error + ">");
	}
});
// Starts the socket listening for connections, does not accept them
listenSocket.listen();
Ti.API.info("Listening now...");

// Tells socket to accept the next inbound connection. listenSocket.accepted gets
// called when a connection is accepted via accept()
Ti.API.info("Calling accept.");
listenSocket.accept({
	timeout : 10000
});

// Call connect after a short timeout to ensure the listening socket is ready to go.
Ti.API.info("Setting timer to connect.");
setTimeout(function(e) {
	Ti.API.info("Calling connect on client socket.");
	clientSocket.connect();
	//listenSocket.isWriteable(); throw an error as undefined is not a function
	listenSocket.isReadable();
}, 500); 

Comments

No comments

JSON Source