Система контроля доступа мобильных пользователей на основе технологии Bluetooth

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование

Скачать Бесплатно!
Для того чтобы скачать эту работу.
1. Пожалуйста введите слова с картинки:

2. И нажмите на эту кнопку.
закрыть



p>

logger.debug("[New connection: IP = " + connection.getRemoteAddress().getHostAddress() + "; Address = " +

connection.getRemoteAddress().getHostName() + ";]");

}

ByteBuffer[] bbuf = connection.readAvailable();

int index = 0;

byte[] buf = null;

for(int i=0; i < bbuf.length; i++)

{

buf = new byte[bbuf[i].capacity()];

for(int k=0; k < buf.length; k++)

buf[k] = bbuf[i].get();

if(cur_gmr.last_msg == null)

cur_gmr.last_msg = new NetMessage();

while( (index = cur_gmr.last_msg.createFromBuffer(buf,index)) > 0)

{

if(cur_gmr.last_msg.complete)

ProcessMsg(cur_gmr);

if(cur_gmr.last_msg == null)

cur_gmr.last_msg = new NetMessage();

}

if(cur_gmr.last_msg != null)

{

ProcessMsg(cur_gmr);

}

buf = null;

}

return true;

}

private void ProcessMsg(NetUser usr)

{

NetMessage nm = null;

Random rnd = null;

List params = null;

boolean status = false;

logger.debug("[" + usr.last_msg.type + " from " + usr.userName + "(" + usr.ID + ")]");

usr.bytes_send += usr.last_msg.body.length;

switch(usr.last_msg.type)

{

case MSGC_LOGIN:

status = userMgr.clientLogin(usr, usr.last_msg.params);

break;

case MSGC_PING:

int userID = (Integer)usr.last_msg.params.get(0);

String key = (String)usr.last_msg.params.get(1);

usr.lastPingTime = MiscFunc.getSeconds();

if(userID != usr.ID && !key.equals(usr.currentKey))

{

logger.info("Client info is wrong!; Removing client from user list");

userMgr.removeClient(usr);

try

{

usr.connection.close();

}

catch (IOException ex)

{

ex.printStackTrace();

}

}

break;

default:

break;

}

usr.last_msg.params.clear();

usr.last_msg = null;

nm = null;

}

public boolean onConnect(INonBlockingConnection connection) throws IOException

{

return true;

}

public boolean onDisconnect(INonBlockingConnection connection) throws IOException

{

NetUser player = userMgr.findByConnection(connection);

if(player != null)

{

logger.info("[Client " + player.userName + "(" + player.ID + ") disconnected]");

userMgr.removeClient(player);

}

else

{

logger.warn("[Unknown client disconnected]");

}

return true;

}

}

 

Клиент :

Main;javax.microedition.midlet.*;javax.microedition.lcdui.*;class BTMidlet extends MIDlet implements CommandListener{

Display display = null;

BTApp game = null;

Form form = null;

TextField textField = null;

int fieldType;

public BTMidlet(){

super();

display = Display.getDisplay(this);

game = new BTApp(this);

display.setCurrent(game);

game.start();

}

public void startApp() {

}

public void pauseApp() {

}

public void destroyApp(boolean unconditional) {

notifyDestroyed();

}

public void quit(){

game.stop();

notifyDestroyed();

}

public void commandAction(Command command, Displayable displayable)

{

}

}

s