Monday, May 16, 2011

[android-developers] ASyNC Socket Read InputStream-Help me

Hi,

I am writing an application that need to interact with remote server.
The situation will be like,

I will send a SOAP request to server ,It sends an message from Server
through Socket Port which need to show as alert message,User have to
select the option(OK/cancel),i have to send the user selection through
to socket output stream. After that it sends actual response to the
request what i sent at the beginning.

I written the implementation as following :
I written the code for sending the request and getting the response in
ASYNC TASK while showing progress dialog in USER screen.
I written a SOCKET listener implementation to read the socket input
stream and write output stream.

I am running service to listen the SOCKET LISTENER class,and am
running a timer with delay of 1000ms to check the socket stream
message.

If i got any message from socket ,it will start an intent to show the
message.

The code is working fine but it is not working on all the occassions.
Some times it is unable to read the stream.

The code here is as follows:
AsynC Socket LISTENER class:

ServerSocket listen = new ServerSocket(port, 1000);

socket = listen.accept();
requestCount++;

InputStream iStream = socket.getInputStream();
int bytesread = 0;

do {
int availbleBytes = iStream.available();
byte[] byte3 = new byte[availbleBytes];
try {
String socketString = new String(byte3,0,byte3.length,"utf-8");
//Log Socket Message
}
}while(availableBytes>0);

Please let me know if any clarifications needed,.
Please help me if you know about socket programming.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate