Results 1 to 3 of 3
  1. #1
    Smollett is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default 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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Client disconnect after 10bytes of data from server websocket.

    the client disconnects saying "error:unknown"
    Is that message yours? Does the catch block have a call to printStackTrace() to give a full error message?

    Please edit you post and wrap the code in code tags. See: BB Code List - Java Programming Forum - Learn Java Programming
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default 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.

    ** This space for rent **

Similar Threads

  1. Calculations in Server side with client`s data
    By thitami in forum Threads and Synchronization
    Replies: 8
    Last Post: 11-19-2011, 03:49 PM
  2. Replies: 4
    Last Post: 09-29-2011, 01:17 PM
  3. Replies: 0
    Last Post: 09-20-2011, 07:50 PM
  4. Replies: 8
    Last Post: 09-24-2010, 03:34 AM
  5. how can i disconnect client?
    By dim_ath in forum New To Java
    Replies: 1
    Last Post: 01-24-2008, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •