• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

custom midlet-servlet chat app problem

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about using a simple HttpConnection between midlet and servlet, instead of Socket-ServerSocket.
 
vuk david
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
vuk david
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply!
I would try to change application in that way.
 
vuk david
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic