I have written a java client code to connect to the server and then login to the server. I am able to connect and My login was successful but its not consistent. I had to run the program again and again as there is a request to be sent after login. it was not sucessfull, The problem is login is not consistent. when i run the program multiple times, sometimes it login and sometimes not.
Please help me.
thanks.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
As noted in the other thread, without details, we cannot help.
Don boscoo
Greenhorn
Joined: Sep 20, 2010
Posts: 28
posted
0
public class Convert extends Thread {
int count = 0;
static Socket socket;
os = new DataOutputStream(socket.getOutputStream());
os.flush();
//byte[] info = new byte[51];
short val = 256;// Login value one.
//short type = swap(val);
//System.out.println( " Swapped Val is $$$$ " + type);
short len = 18944;// The length of the packet
//sending packet as per the rules.
os.writeShort(len);
os.writeShort(val);
os.writeBytes("username");
os.writeByte(0);
os.writeByte(0);
os.writeByte(0);
os.writeByte(0);
os.writeBytes("password");
os.writeByte(0);
os.writeByte(0);
os.writeByte(0);
os.writeByte(0);
os.writeByte(0);
os.writeByte(0);
os.writeByte(0);
// os.writeBytes(bin);
os.writeByte(0); // optional
os.writeBytes("client detils");
os.flush();
Next time please edit your post instead of posting it again.
Your code doesn't compile. A variable is missing and a bracket is wrong. But you still haven't told us the real problem. Please TellTheDetails. What does happen and what do you expect to happen? And the code you posted is only on the client side. We don't know what the server is expecting and returning.
There is an unnecessary flush and your flushh method has two h's.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Don boscoo
Greenhorn
Joined: Sep 20, 2010
Posts: 28
posted
0
Hey thanks for the reply. I cleared the braces problem and the double 'h' in flushh is the method i've written different from the flush method.
I have to connect to the sever and then login to the server .After establishing the connection,(connectserver method)
The login packet is sent as per the specifications.(login() method)
After sending the requeste we have return codes as per the specification.
When i made the request for login it was sucessfull.
But the problem is, It is not consistent.
when i compile multiple times, Its successfull once and unsucessful again after recomplilation within next few seconds.
How do i make it consistent, even if i recompile it. The error which am gettin after recompiling is BAD_REQUEST_BUFFER(this is a return code as per the specification). I wonder if there is a problem while calling with the InputStream.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
What's "short len = 18944;// The length of the packet" all about? Is there some other definition of "packet length" that's not associated with the length of the packet?
Don boscoo
Greenhorn
Joined: Sep 20, 2010
Posts: 28
posted
0
thats the unicode value which is suppose to be 74 in decimal. I tried sending either way but no difference. In the packet sequence the length of the packet and the type of the packet is to be sent as per the specification first.
In the result the out put is in unicode , thats why i divided the result by 256 to get in decimal to check with the return codes in the specification which is mentioned in decimal.
Which specification are you referring to? Also see this about extending a Thread.
Don boscoo
Greenhorn
Joined: Sep 20, 2010
Posts: 28
posted
0
I am refering to the specs i've been given.
Thanks.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
You do understand that since *we* don't have those specs, any help we offer is pure *spec*ulation, right?
Don boscoo
Greenhorn
Joined: Sep 20, 2010
Posts: 28
posted
0
we have a c++ code running this application. It has to be converted to java. Now my question is, Do we need to write the server socket program too for the socket communication?
As of now I've written the client program and making a request to the server.
If you are not allowed to disclose that spec then just say so. Otherwise we'll keep asking for it. Java has a ServerSocket class so no you don't have to write that. You can try to analyze your output with a packet sniffer like Wireshark and compare it to what you want it to output.