1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 function Client( aServerAddress
) {
11 var mReceiveBuffer
= "";
12 var mCurrentMessage
= [];
14 var mReceiver
= new Receiver();
17 this.sendMessage = function( aMessage
) {
18 mSocket
.send( aMessage
);
22 function dataReceived( aEvent
) {
23 mReceiveBuffer
+= aEvent
.data
;
25 while ( ( i
= mReceiveBuffer
.indexOf( '\n' ) ) != -1 ) {
26 var aLine
= mReceiveBuffer
.substring( 0, i
);
27 mReceiveBuffer
= mReceiveBuffer
.substring( i
+1 );
28 if ( aLine
.length
> 0 ) {
29 mCurrentMessage
.push( aLine
);
31 mReceiver
.parseMessage( mCurrentMessage
);
39 if( navigator
.mozTCPSocket
) {
40 mSocket
= navigator
.mozTCPSocket
.open( "localhost", 1599 );
41 mSocket
.onopen = function( aEvent
) {
42 console
.log( "Received onopen" );
43 mSocket
.send( "LO_SERVER_CLIENT_PAIR\nFirefox OS\n1234\n\n" );
45 mSocket
.onerror = function( aEvent
) {
46 console
.log( "Received error: " + aEvent
.data
);
48 mSocket
.ondata
= dataReceived
;
50 console
.log( "Can't access socket." );
54 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */