[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:
public static void sendback(String what2send) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(mySocket.getOutputStream());
log.info("Got text: "+ what2send);
oos.writeBytes(what2send);
oos.flush();
}
now, on vb, i am using:
VB Code:
Dim received As Byte()
received = New Byte(1023) {}
Dim readbytes As Integer = 0
readbytes = clientSocket.GetStream().Read(received, 0, received.Length)
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.
Re: receiving chat from a java chat server...
You're reading twice in a row, so there's nothing left to read.
Re: receiving chat from a java chat server...
so, which do you recommend i do?
Re: receiving chat from a java chat server...
Modified the read code to:
vb Code:
Dim inStream(10024) As Byte
Dim buffsize As Integer
buffSize = clientSocket.ReceiveBufferSize
serverStream.Read(inStream, 0, buffSize)
Dim returndata As String = _
System.Text.Encoding.ASCII.GetString(inStream)
Debug.Print("Data from Server : " + returndata)
however, that's returning, "Data from server : ??"
Re: receiving chat from a java chat server...
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.
Re: receiving chat from a java chat server...
It now returns, a black triangle with a ? in it. 2 of them.
��
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.