- Home /
Is it possible to send whole bytearray at once? JS
Hi. Currently I have client, that creates TcpClient and using TcpClient.Connect() creates a connection to server and finally NetworkStream using client.getStream();
private function ThreadListener(){
var client = new TcpClient();
var port = 66948;
try{
client.Connect(IPEndPoint(IPAddress.Parse("127.0.0.1"), port));
ns = client.GetStream();
/*.
.
.*/
}
catch (InvOpEx : InvalidOperationException) {
Debug.Log("TCP exception: " + InvOpEx.Message);
}
catch (SockEx : SocketException) {
Debug.Log("Socket exception: " + SockEx.Message);
}
finally {
if(ns != null)
ns.Close();
client.Close();
}
}
After NetworkStream is made, I can transfer byte arrays over it, one byte at a time using:
var bytes : byte[] = System.Text.Encoding.ASCII.GetBytes("String to bytes");
if(ns.CanWrite){
ns.Write(bytes, 0, bytes.Length);
}
However, when using Java server, it receives the String one byte at a time when using:
Socket.getOutputStream();
I'm wondering, do I have to make edits to my server side or is there anyway to make NetworkStream send whole bytearray at once, instead of one byte at a time?
Your answer
Follow this Question
Related Questions
Very Confused on Networking HLAPI Practices 1 Answer
Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers
"Trying to send command for object without authority" warning but the object is the localPlayer 1 Answer
All players number in Network 1 Answer
Question regarding Server-Client approach in Unity 0 Answers