• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chat Server for JME

 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try running in a debugger with a break point on Client#connect?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try flushing the stream after writing to it.
 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic