mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
proxy now writes one byte to relay and reads one byte reply.
This commit is contained in:
parent
48ac79be51
commit
56b6a425e2
2 changed files with 36 additions and 10 deletions
|
@ -27,9 +27,17 @@ import android.os.IBinder;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import javax.net.SocketFactory;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public class RelayService extends Service {
|
public class RelayService extends Service {
|
||||||
|
|
||||||
|
private static final String proxy_addr = "10.0.2.2";
|
||||||
|
private static final int proxy_port = 10998;
|
||||||
|
|
||||||
private NotificationManager m_nm;
|
private NotificationManager m_nm;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,8 +46,29 @@ public class RelayService extends Service {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
Utils.logf( "RelayService::onCreate() called" );
|
Utils.logf( "RelayService::onCreate() called" );
|
||||||
|
|
||||||
|
Thread thread = new Thread( null, new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
SocketFactory factory = SocketFactory.getDefault();
|
||||||
|
InetAddress addr = InetAddress.getByName( proxy_addr );
|
||||||
|
Socket socket = factory.createSocket( addr, proxy_port );
|
||||||
|
socket.setSoTimeout( 3000 );
|
||||||
|
Utils.logf( "writing to proxy socket" );
|
||||||
|
OutputStream outStream = socket.getOutputStream();
|
||||||
|
outStream.write( 0 );
|
||||||
|
InputStream inStream = socket.getInputStream();
|
||||||
|
int result = inStream.read();
|
||||||
|
socket.close();
|
||||||
|
Utils.logf( "read %d and closed proxy socket", result );
|
||||||
|
} catch( java.net.UnknownHostException uhe ) {
|
||||||
|
Utils.logf( uhe.toString() );
|
||||||
|
} catch( java.io.IOException ioe ) {
|
||||||
|
Utils.logf( ioe.toString() );
|
||||||
|
}
|
||||||
|
|
||||||
Thread thread = new Thread( null, m_task, getClass().getName() );
|
RelayService.this.stopSelf();
|
||||||
|
}
|
||||||
|
}, getClass().getName() );
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,13 +112,5 @@ public class RelayService extends Service {
|
||||||
// m_nm.notify( R.string.running_notification, notification );
|
// m_nm.notify( R.string.running_notification, notification );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Thread that does the actual work of pinging the relay
|
|
||||||
private Runnable m_task = new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
RelayService.this.stopSelf();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -931,7 +931,12 @@ main( int argc, char** argv )
|
||||||
|
|
||||||
tPool->AddSocket( newSock );
|
tPool->AddSocket( newSock );
|
||||||
} else {
|
} else {
|
||||||
logf( XW_LOGERROR, "can't handle device socket yet" );
|
unsigned char one;
|
||||||
|
read( newSock, &one, 1 );
|
||||||
|
logf( XW_LOGERROR, "new socket connected; read %d", one );
|
||||||
|
one = 1;
|
||||||
|
write( newSock, &one, 1 );
|
||||||
|
close( newSock );
|
||||||
}
|
}
|
||||||
|
|
||||||
--retval;
|
--retval;
|
||||||
|
|
Loading…
Reference in a new issue