• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

AWT-server socket issue

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am developing a client server application based on server sockets. The client has a GUI written in AWT and the server has methods to process requests sent to it from the client
I have successfully made a connection between server and client and sent requests and received requests using matching pairs of BufferedReaders and PrintWriters. In the actionPerformed of the client the printWriter will send out requests depending on which button is pressed and the buffered reader on the server will receive the request and the relevant processing should commence. The server PrintWriter should then send the result back to the clients BufferedReader
[1] The first problem is that when I send a request to the server to return the result of a search the application locks when there are multiple lines of text in the reply which for the moment I am just outputting to the client's system out.
[2] The second issue is that once I resolve the locking issue above I want to change from printing the results of queries to the system.out and instead update text components in the client GUI with the information returned. There is a list component and two textfield components which should display info related to the item selected in the list.

If you know how to get round this please let me know and I can send you further code if necessary:
I think this is where part of the problem is:
In client:
public void actionPerformed( ActionEvent e ) {
String buttonPressed=e.getActionCommand();
try{
if(buttonPressed.equals("search")){
String name=kfc.getText(); //kfc is the textfield where a name is entered to search on
String x;
x="<"+name;
out.println(x);
String text;
while ((text = in.readLine()) != null) //in is the bufferedReader
{
System.out.println(text);
out.println("search info received");
}
in.close(); //may not need this here
}
} catch (IOException f){
System.out.println("Read failed");
System.exit(1);
}

In the server:
do {
s = br.readLine();
if(s.startsWith("<")) {
String y=s.substring(1,s.length());
for (Enumeration e=membs.getMember(y);e.hasMoreElements() {
outer.println(e.nextElement());
}

Any tips would be greatly appreciated.
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic