pls clarify this .[reading data using streamconnection ]

Forum for discussion about developing multiplayer games for mobile platform including Httpconnection and bluetooth connections.

pls clarify this .[reading data using streamconnection ]

Postby itskrishnaraj » Thu Dec 04, 2008 1:28 pm

hi code tiger

In my application [ bluetooth application ] i am sending some byte array values, and i have to read or recieve the same data any where in the code. but i can only read data from some particular place only like

public void servicesDiscovered(int transID, ServiceRecord[] servRecord)
{
System.out.println("ServicesDiscovered");

// in this example there is only one service
for(int i=0;i<servRecord.length;i++)
{
serviceUrl = servRecord[i].getConnectionURL(0,false); //here m getting the url ..but i can't use this url globally...! ...why?
}
}

public void serviceSearchCompleted(int transID, int responseCode)
{
if(responseCode == SERVICE_SEARCH_ERROR)
System.out.println("SERVICE_SEARCH_ERROR\n");

if(responseCode == SERVICE_SEARCH_COMPLETED)
{
System.out.println("SERVICE_SEARCH_COMPLETED\n");
System.out.println("Service URL: " + serviceUrl+"\n\n");
try
{

clientConn = (StreamConnection) Connector.open(serviceUrl); //i can use the ural here .i mean can't use this clientConn some where else, it will return null......! why....?
output = clientConn.openOutputStream();
input = clientConn.openInputStream();

replayData=new byte[10];
StringBuffer bufferVal = new StringBuffer();
int ch=0;
try
{
while ( ( ch = input.read() ) != -1)
{
bufferVal.append( (char) ch );
}
replayData = bufferVal.toString().getBytes(); //here am getting the data [ some 10 bytes ]

for(int m=0;m<replayData.length;m++)
{
System.out.println("Received replayData--[ "+m+" ]--> "+replayData[m]);
}
System.out.println("\n\n");
}
catch (IOException e)
{
System.err.println(e.toString());
}





if(replayData!=null)
changeState(GAMESTATE_OPPONENT_INIT_MOVE); //changing the game state

}
catch(IOException ioe)
{
System.out.println("error in connection service search complete");
}

}

if(responseCode == SERVICE_SEARCH_TERMINATED)
System.out.println("SERVICE_SEARCH_TERMINATED\n");

if(responseCode == SERVICE_SEARCH_NO_RECORDS)
System.out.println("SERVICE_SEARCH_NO_RECORDS\n");

if(responseCode == SERVICE_SEARCH_DEVICE_NOT_REACHABLE)
System.out.println("SERVICE_SEARCH_DEVICE_NOT_REACHABLE\n");
}


pls help me to sort dis out.....

thanks in advance
kris
itskrishnaraj
 
Posts: 39
Joined: Thu Aug 07, 2008 1:28 pm

Return to Multiplayer Mobile Games

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron