aspose file tools*
The moose likes Java Micro Edition and the fly likes Chat Server for JME Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Chat Server for JME" Watch "Chat Server for JME" New topic
Author

Chat Server for JME

Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Hi,

I am trying to create a chat server with Servlets for JME chat application.When i use socket connection in Java this works fine. But when i implement the code with sockets in a servlet, it doesn't connect. I have given the testing codes below. Can you please help me?

JME Code:



Servlet code:




Server Thread:


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
--- Martin Fowler
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10522
    
    9

But when i implement the code with sockets in a servlet, it doesn't connect. I have given the testing codes below. Can you please help me?

ItDoesntWorkIsUseless
TellTheDetails

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

As you see, I have started it the java file as a new thread. I use GlassFish Server 4.0 in NetBeans 7.3.1. The statement "Inside run" is printed as Info:Inside run in the Server output. After that INFO: JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://192.168.104.129:8686/jndi/rmi://192.168.104.129:8686/jmxrmi is printed. When i try to run the JME app in the emulator, I don't see anything happening, both keep running no exceptions or errors occur.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10522
    
    9

Did you try running in a debugger with a break point on Client#connect?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Since the server is an HTTP server, you can test whether it works using a browser. That's what I would start with.

As to the client, add some print statements to the send and connect methods to check whether they're being called, and run successfully. (I'm assuming that JME has logging facilities that work in its emulator.)


Ping & DNS - my free Android networking tools app
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Maneesh,

Sorry but I don't know how to do that can you please guide me?

Ulf,

Yes I check my server with the browser every time before I run and I also check the client. Everything works fine till connect method in client and as for send method the statement r.setText("Hello") works fine.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Try flushing the stream after writing to it.
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267


Ulf,

I am not able to connect the server and client. Can I flush the stream without connections? In the server java file, all works until the line "cs =ss.accept()". After that line nothing happens. But on client side, if I give a print statement after "dos = new DataOutputStream(scon.openDataOutputStream());", it prints. This means the output stream is open right? If I am wrong in any part, Please correct me.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Can I flush the stream without connections?

What happened when you tried?

In the server java file, all works until the line "cs =ss.accept()". After that line nothing happens.

Read the javadocs of that method to learn why that is so.
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Ulf,

The same result even after using flush(). Nothing happened.

And as for accept(), it is written in javadoc as

Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.


So we can conclude that connection is not accepted.

I tried different servers too, like "www.forum.nokia.com" and some custom created servers from weebly and other sites.

Do I need to change something in the web.xml file?

Please help me.

I am seriously frustrated by this connection.

When i use debugger the following lines occur in debugger console, I am not sure what happens

Listening on javadebug
User program running
LineBreakpoint TestServer.java : 28 successfully submitted.
Breakpoint hit at line 28 in class TS.TestServer by thread Thread-0.
Thread Thread-0 stopped at TestServer.java:28.
User program running
Thread Thread-0 stopped at DualStackPlainSocketImpl.java.accept0.

Do I need to send headers to the servlet?
If what should I send in "POST"+ ?? +"HTTP/1.1 rn"

I have opened the servlet in Java web project. Do I need to change it to a Java EE project?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
So this is supposed to be HTTP communication? In that case, why is there a server socket at all? The servlet should be able to handle the entire server functionality, no?

So we can conclude that connection is not accepted.

I don't see anything that would lead me to conclude that.

Maybe http://www.java2s.com/Code/Java/J2ME/HttpConnection.htm or http://www.wirelessdevnet.com/channels/java/features/j2me_http.phtml helps.
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267


Ulf and Maneesh,

Thanks for your continuous reply. I have already seen these two examples. I did the worst mistake. I did not upload my updated files to my sever. Anyways thanks for your help. In case I need more help I will post here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chat Server for JME