I just googled: "java async socket"
And got this tutorial:
http://games.fabiolee.com/post.asp?id=418

I'm not sure if it helps...

Moto!


On Jul 14, 11:17 am, Walter <[email protected]> wrote:
> You usually need different threads to read  and write, prevent
> blocking the UI thread.
>
> On Jul 14, 12:49 am, Victor Lin <[email protected]> wrote:
>
> > Well, but will the read of InputStream blocked when there is no
> > incoming data?
> > I mean... for example:
>
> > I run the sock in specific thread, because those methods' call will
> > blocked. The code might like this:
>
> > /// This is the socket thread for checking data
> > while not stop:
> >     data = read(); // if no incoming data, we will blocked here
>
> > The client program needs to check the data from sever, so it run a
> > loop to read data. And how about outgoing data? Can I send out going
> > data from another thread? like this.
>
> > // this is called from UI thread
> > void onClick() {
> >     outputStream.write("hello baby!");
>
> > }
>
> > On 7月14日, 下午2時21分, James <[email protected]> wrote:
>
> > > Hi Victor Lin:
> > > I don't know why could your problem happen,As One socket have both
> > > inputstream and outputstreams,They are responsible for read and write;
> > > And as far as i call tell,Socket is not android-specified,Hope this
> > > helps!
>
> > > Bgs!
> > > James
>
> > > On Jul 14, 12:57 pm, Victor Lin <[email protected]> wrote:
>
> > > > Hi,
>
> > > > I am developing a program that needs async socket. I am new to Android
> > > > and Java. As I can see in the document, to write network program, I
> > > > got Socket and SocketChannel, but it seems they are all sync socket,
> > > > it means, I need an extra thread to call blocking read, write... and
> > > > etc. Here comes the problem, my program is a chat room, the
> > > > communicate is not linear, I have no idea when the server will send a
> > > > message to me, if I read in that thread to wait message from server,
> > > > but the user want to send message to server, the reading function
> > > > blocked forever, if there is no incoming data, then the pending
> > > > outgoing message will not be sent. That's why I need async socket. So
> > > > my question is: How to write async socket under Android environment?
>
> > > > Thanks.
> > > > Victor Lin.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to