@@ -19,6 +19,7 @@ export class HL7Socket extends AsyncEventEmitter<HL7Socket.Events> {
1919 protected _frameStream : FrameStream ;
2020 protected _waitPromises = new Set < Promise < any > > ( ) ;
2121 protected _options : HL7Socket . Options ;
22+ protected _peerIp : string ;
2223 responseTimeout ?: number ;
2324 /**
2425 * User defined property
@@ -36,7 +37,12 @@ export class HL7Socket extends AsyncEventEmitter<HL7Socket.Events> {
3637 maxBufferSize : options ?. maxBufferSize ,
3738 } ) ;
3839 this . _frameStream = frameStream ;
39- socket . on ( 'error' , err => this . emit ( 'error' , err ) ) ;
40+ socket . on ( 'error' , ( err : any ) => {
41+ if ( err . code === 'ECONNRESET' ) {
42+ err . message = `Connection reset by peer` ;
43+ }
44+ this . emit ( 'error' , err ) ;
45+ } ) ;
4046 socket . pipe ( frameStream ) ;
4147 socket . on ( 'connect' , ( ) => this . emit ( 'connect' ) ) ;
4248 socket . on ( 'ready' , ( ) => this . emit ( 'ready' ) ) ;
@@ -51,6 +57,9 @@ export class HL7Socket extends AsyncEventEmitter<HL7Socket.Events> {
5157 this . emit ( 'data' , data ) ;
5258 this . _onData ( data ) ;
5359 } ) ;
60+ this . _peerIp = ( socket . address ( ) as any ) ?. address || '' ;
61+ if ( this . _peerIp . lastIndexOf ( ':' ) !== - 1 )
62+ this . _peerIp = this . _peerIp . substring ( this . _peerIp . lastIndexOf ( ':' ) + 1 ) ;
5463 }
5564
5665 get connected ( ) : boolean {
@@ -78,8 +87,7 @@ export class HL7Socket extends AsyncEventEmitter<HL7Socket.Events> {
7887 }
7988
8089 peerIp ( ) {
81- const address : any = this . socket . address ( ) ;
82- return address . address ;
90+ return this . _peerIp ;
8391 }
8492
8593 get writable ( ) {
0 commit comments