mirror of https://github.com/nodejs/node.git
Add callback paramenter to socket.connect()
parent
c4161f32f5
commit
632da2a393
|
@ -153,8 +153,8 @@ and passed to the user through the `'connection'` event of a server.
|
||||||
|
|
||||||
`net.Stream` instances are EventEmitters with the following events:
|
`net.Stream` instances are EventEmitters with the following events:
|
||||||
|
|
||||||
#### stream.connect(port, [host])
|
#### stream.connect(port, [host], [callback])
|
||||||
#### stream.connect(path)
|
#### stream.connect(path, [callback])
|
||||||
|
|
||||||
Opens the connection for a given stream. If `port` and `host` are given,
|
Opens the connection for a given stream. If `port` and `host` are given,
|
||||||
then the stream will be opened as a TCP stream, if `host` is omitted,
|
then the stream will be opened as a TCP stream, if `host` is omitted,
|
||||||
|
@ -170,6 +170,9 @@ stream is established. If there is a problem connecting, the `'connect'`
|
||||||
event will not be emitted, the `'error'` event will be emitted with
|
event will not be emitted, the `'error'` event will be emitted with
|
||||||
the exception.
|
the exception.
|
||||||
|
|
||||||
|
The `callback` paramenter will be added as an listener for the 'connect'
|
||||||
|
event.
|
||||||
|
|
||||||
|
|
||||||
#### stream.setEncoding(encoding=null)
|
#### stream.setEncoding(encoding=null)
|
||||||
|
|
||||||
|
|
|
@ -638,6 +638,11 @@ Stream.prototype.connect = function() {
|
||||||
self._connecting = true; // set false in doConnect
|
self._connecting = true; // set false in doConnect
|
||||||
self.writable = true;
|
self.writable = true;
|
||||||
|
|
||||||
|
var lastArg = arguments[arguments.length - 1];
|
||||||
|
if (typeof lastArg == 'function') {
|
||||||
|
self.addListener('connect', lastArg);
|
||||||
|
}
|
||||||
|
|
||||||
var port = toPort(arguments[0]);
|
var port = toPort(arguments[0]);
|
||||||
if (port === false) {
|
if (port === false) {
|
||||||
// UNIX
|
// UNIX
|
||||||
|
|
|
@ -33,10 +33,7 @@ tcp.listen(common.PORT, function () {
|
||||||
|
|
||||||
console.log('Connecting to socket');
|
console.log('Connecting to socket');
|
||||||
|
|
||||||
socket.connect(tcpPort);
|
socket.connect(tcpPort, function() {
|
||||||
|
|
||||||
|
|
||||||
socket.on('connect', function() {
|
|
||||||
console.log('socket connected');
|
console.log('socket connected');
|
||||||
connectHappened = true;
|
connectHappened = true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue