The Artima Developer Community
Sponsored Link

Java Answers Forum
Java server client problem

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
jamal jamal

Posts: 1
Nickname: jamaldb
Registered: May, 2009

Java server client problem Posted: May 31, 2009 4:14 AM
Reply to this message Reply
Advertisement
hello guys
i am facing some problem with my client program when it is writing to sever. My intention is to send command to the server. Its working fine when I am sending single command for example:

OutputStreamWriter out=new OutputStreamWriter(sock.getOutputStream());
out.write("user jamal");
out.flush();

but it seems that write appending when I am trying to write two or more command

OutputStreamWriter out=new OutputStreamWriter(sock.getOutputStream());
out.write("user xyz");
out.flush();

out=new OutputStreamWriter(sock.getOutputStream());
out.write("pass 12345");
out.flush();

on the server side it should be read twice

further more when I am using a thread.sleep() between command/write it working fine

sorry about my english. Please suggest me what to do with my client.

Code of server part dealing with client :

sendResponse(200, "Ok");

MethodExecutor cmd_parser=new MethodExecutor(channel,this);
int i=1;
while(m_sock!=null){
System.out.println("Reading Command:"+i);
int rdlen=m_in.read(m_inbuf);



if(rdlen==-1)
{
closeSession();
break;
}

if ( rdlen > 0) {
while (rdlen > 0 && m_inbuf[rdlen - 1] == '\r' || m_inbuf[rdlen - 1] == '\n')
rdlen--;
}

String cmd = new String(m_inbuf,0,rdlen);
System.out.println(cmd);
cmd_parser.execute(cmd);

i++ ;
}

Topic: JDK Download Site - What happened to being User Friendly?? Previous Topic   Next Topic Topic: On JVM-based languages

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use