aspose file tools*
The moose likes Java Micro Edition and the fly likes custom midlet-servlet chat app problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "custom midlet-servlet chat app problem" Watch "custom midlet-servlet chat app problem" New topic
Author

custom midlet-servlet chat app problem

vuk david
Greenhorn

Joined: Sep 22, 2009
Posts: 5
Hi, sorry for my bad english.
I have a big problem with developing chat application, so I really hope you can help me out.

I created a chat midlet application and java server, who works on my home computer with 24/7 adsl network connection. This works fine. Connection between midlet and servlet is via sockets (Socket - ServerSocket).

My problem is that I want to upload my server to some java hosting free provider and use it without my local computer.

I modified my server into servlet, and that works just fine in Netbeans Tomcat java server. But when I upload it on free server http://eatj.com/ it wont work. I figure it out that the problem is in sockets, and online server don't allow it.

I run out of ideas how to make it work.

I could change my app to work with servlet get post methods, but I don't know how.

Thanks for any reply..
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

How about using a simple HttpConnection between midlet and servlet, instead of Socket-ServerSocket.


Swastik
vuk david
Greenhorn

Joined: Sep 22, 2009
Posts: 5
Thanks for replay Swastik Dey.

I try to use HttpConnection class, but I dont know how to keep connection alive (like i use to in Socket-ServerSocket connection).
When I connect to servlet, I open DataOutputStream and DataInputStream. I suppose that my method of sending data is POST. This works fine when I send data to servlet, and receve it. But after that, http servlet seems to close connection and when I try to send another data I get java.io.IOException: connection is not open.

I don't understand how to implement chat when my connection is always become closed, and I need to reopen it.

Am I missing something?

Thanks for any advise...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15657
    
  15

Yes. HTTP protocol is not a continuous conversation. It's a series of request/response cycles and each one is a separate connection opened and closed. That's a basic architectural restriction. To get around that, you'd have to make your chat client send a request periodically to poll for new chat info, since HTTP doesn't allow unsolicited responses either.


Customer surveys are for companies who didn't pay proper attention to begin with.
vuk david
Greenhorn

Joined: Sep 22, 2009
Posts: 5
Thanks for reply!
I would try to change application in that way.
vuk david
Greenhorn

Joined: Sep 22, 2009
Posts: 5
I could make something like this:

while (true) {
// create new request message
// open connection
// send a message (if any) as a request
// receive incoming message (if any) as reply
// close connection
// handle reply
Thread.sleep(200);
}

But that means that my midlet will send and recieve some sort of data every 0.2sec. And if I just open my app, and leave it for 30min I will get a lot of bytes transfered via GPRS, and my mobile operator will charge it.

Is there any other solution? To get replay from servlet when actually needed to be sent?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15657
    
  15

vuk david wrote:

Is there any other solution? To get replay from servlet when actually needed to be sent?


No, because a reply, you first have to ask a question. Otherwise it isn't a reply, it's a statement, prompt, unsolicted message, or whatever you want to call it. And as long as you use HTTP as your transport mechanism, you can't do that.

Actually, there'd be no place to send it to. In TCP/IP, to send something, you need 2 things: a destination IP address and a destination port number. In HTTP, the destination (reply) port is acquired when the request starts and released when the response has been received. A very high probability exists that a completely different reply port will be used on each subsequent request/response cycle, so there's no predetermined destination port that the server could contact.
vuk david
Greenhorn

Joined: Sep 22, 2009
Posts: 5
OK, thanks for reply.

I will use then my home ADSL connection and sockets. Because I didn't find a right solution in HTTP connection how to make my server online.

Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: custom midlet-servlet chat app problem
 
Similar Threads
LDAP and SSL behavior in iPlanet 6.1
communication problem in chat application.....Please help!!
Chat not Working through Proxy? PLz advice
Midlet not working on phone
Second Time: MIDlet cann't connect to servlet on website