Results 1 to 3 of 3
- 01-27-2013, 04:09 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 2
- Rep Power
- 0
Client disconnect after 10bytes of data from server websocket.
I managed to get past the handshake stage of the client server websocket connection but now i have a problem sending data from the server to the client. Here is the code that sends the data:
public void Send(String s)throws IOException{
os = socket.getOutputStream();
byte[] rawData = s.getBytes("UTF-8");
int frameCount = 0;
byte[] frame = new byte[10];
frame[0] = (byte) 129;
if(rawData.length <= 125){
frame[1] = (byte) rawData.length;
frameCount = 2;
}else if(rawData.length >= 126 && rawData.length <= 65535){
frame[1] = (byte) 126;
byte len = (byte) rawData.length;
frame[2] = (byte)((len >> 8 ) & (byte)255);
frame[3] = (byte)(len & (byte)255);
frameCount = 4;
}else{
frame[1] = (byte) 127;
byte len = (byte) rawData.length;
frame[2] = (byte)((len >> 56 ) & (byte)255);
frame[3] = (byte)((len >> 48 ) & (byte)255);
frame[4] = (byte)((len >> 40 ) & (byte)255);
frame[5] = (byte)((len >> 32 ) & (byte)255);
frame[6] = (byte)((len >> 24 ) & (byte)255);
frame[7] = (byte)((len >> 16 ) & (byte)255);
frame[8] = (byte)((len >> 8 ) & (byte)255);
frame[9] = (byte)(len & (byte)255);
frameCount = 10;
}
int bLength = frameCount + rawData.length;
byte[] reply = new byte[bLength];
int bLim = 0;
for(int i=0; i<frameCount;i++){
reply[bLim] = frame[i];
bLim++;
}
for(int i=0; i<rawData.length;i++){
reply[bLim] = rawData[i];
bLim++;
}
System.out.println(frame);
os.write(reply);
os.flush();
}
That is supposed to send the string s to the client. I can send 9bytes of data but it is not received by the test client at echo websocket website, and if i send a tenth byte, the client disconnects saying "error:unknown". Any idea what i am doing wrong? Thanks in advance! Smollett.
- 01-28-2013, 10:01 PM #2
Re: Client disconnect after 10bytes of data from server websocket.
Is that message yours? Does the catch block have a call to printStackTrace() to give a full error message?the client disconnects saying "error:unknown"
Please edit you post and wrap the code in code tags. See: BB Code List - Java Programming Forum - Learn Java ProgrammingIf you don't understand my response, don't ignore it, ask a question.
- 01-29-2013, 09:34 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Client disconnect after 10bytes of data from server websocket.
And when you've done both those things, stick some println debugging in that code up there so you can see exactly what route it is taking through your code, and what it is attempting to send.
Please do not ask for code as refusal often offends.
Similar Threads
-
Calculations in Server side with client`s data
By thitami in forum Threads and SynchronizationReplies: 8Last Post: 11-19-2011, 03:49 PM -
java server client socket sending and reading data HELP!
By mrhid6 in forum Java GamingReplies: 4Last Post: 09-29-2011, 01:17 PM -
How to get IP and port of client in onOpen() method using Jetty's WebSocket?
By stodge in forum New To JavaReplies: 0Last Post: 09-20-2011, 07:50 PM -
send multiple ints of data from the server to the client..
By lkcz in forum New To JavaReplies: 8Last Post: 09-24-2010, 03:34 AM -
how can i disconnect client?
By dim_ath in forum New To JavaReplies: 1Last Post: 01-24-2008, 04:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks