• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

client / server (communication problem...)

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i need to create a little client/server (multithread)

i read
http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

i don't need the protocol class (just need to return what the client type and the number of request...)

the connection is ok but when the client type... nothing happen on the server

client class


server class


ServerThread class


PrintWriter and BufferedReader seem ok...
any idea?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi marc,

the server code is fine - you may test it by connecting to your server with a telnet client and then typing a line.

however, the client expects the server to send a welcome string once they are connected. it hangs at:


because the server also waits for the client to send something, which doesn't happen!
 
mark smith
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok but how can i resolve the problem
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this out.
like this, there is no loop or so, but you can see what you type in at the client will be received by the server. Now just do whatever you wanted to do with the data coming in at the server.
One caveat. When you run the client from an IDE, you might get problems because sometimes, STDIN (java.lang.System.in) is not readable (BufferedReader.readLine() in the client then returns immediately). I have this problem when I use my Netbeans IDE. Netbeans uses Ant for running a project, and by default you don't have a console (there is some kind of switch you can set in the "java" ant task, it's attribute "fork" which you probably have to set to "true" if you wanna use the Netbeans console as STDIN; see manual: http://ant.apache.org/manual/index.html). I recommend testing from the command line.


[ September 28, 2005: Message edited by: Dennis K�hn ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have done this and am facing the same problem "client don't get the result from the server".....need help


Client code:




Multi-Server code:






Thread code:





i have changed things according to the previous explenation but still
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Colinm and sama xxx

Both of you, welcome to JavaRanch!

And I do have to let you know that you're both in violation of the JavaRanch policy on display names. It requires that you use a full, real (sounding) first and last name for your display name. Joke names and "handles" aren't acceptable at the Ranch. You can change your display names here; please do so right away. Thanks for your cooperation.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LOL no one seems to offer help in here
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic