Results 1 to 8 of 8

Thread: [RESOLVED] receiving chat from a java chat server...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Resolved [RESOLVED] receiving chat from a java chat server...

    Hello everyone,

    So, in another related post, i got the chat to send to a java server, cool.


    Now, it's a matter of sending it back to VB.


    on the server side of things, (in java), I am using the following code:

    JAVA Code:
    1. public static void sendback(String what2send) throws IOException {
    2.         ObjectOutputStream oos = new ObjectOutputStream(mySocket.getOutputStream());
    3.         log.info("Got text: "+ what2send);
    4.         oos.writeBytes(what2send);
    5.         oos.flush();
    6.     }

    now, on vb, i am using:

    VB Code:
    1. Dim received As Byte()
    2.             received = New Byte(1023) {}
    3.             Dim readbytes As Integer = 0
    4.             readbytes = clientSocket.GetStream().Read(received, 0, received.Length)
    5.             Debug.Print("Output from server: " & serverStream.Read(received, 0, readbytes))

    it seems to be freezing on the serverStream.read portion.

    Now, I am no expert to sockets, and am able to do a vb to vb client/server chat, however going from java to vb is way new to me.

    Any help or guidance would be GREATLY appreciated.

  2. #2

    Re: receiving chat from a java chat server...

    You're reading twice in a row, so there's nothing left to read.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: receiving chat from a java chat server...

    so, which do you recommend i do?

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: receiving chat from a java chat server...

    Modified the read code to:

    vb Code:
    1. Dim inStream(10024) As Byte
    2.             Dim buffsize As Integer
    3.             buffSize = clientSocket.ReceiveBufferSize
    4.             serverStream.Read(inStream, 0, buffSize)
    5.             Dim returndata As String = _
    6.             System.Text.Encoding.ASCII.GetString(inStream)
    7.             Debug.Print("Data from Server : " + returndata)

    however, that's returning, "Data from server : ??"

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: receiving chat from a java chat server...

    bump

  6. #6

    Re: receiving chat from a java chat server...

    Two things:
    1) Do not bump your thread needlessly so fast. It's pointless and clutters up the thread.
    2) Change your encoding type around to see if that fixes the problem. Instead of using ASCII, try using UTF8. However, your inStream() Byte array is improperly sized. In fact, I would declare it like so:

    Code:
    Dim inStream(clientSocket.ReceiveBufferSize - 1) As Byte
    Dim bytesRead As Integer = 0
    bytesRead = serverStream.Read(inStream, 0, inStream.GetUpperBound(0))
    Array.Resize(inStream, bytesRead)
    Dim returnData As String = System.Text.Encoding.UTF8.GetString(inStream)
    Debug.WriteLine(returnData)
    See what happens there.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: receiving chat from a java chat server...

    It now returns, a black triangle with a ? in it. 2 of them.

    ��

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2007
    Posts
    520

    Re: receiving chat from a java chat server...

    we got it fixed. it was on the java side of things messing it all up. thanks for the help.

Posting Permissions

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



Click Here to Expand Forum to Full Width