TcpClient
hi all,
i building tcp listener is supposed capture data device in our network. device broadcasting data comma delimited. example: datfield1, datafield2, datafield3, etc. @ times device transmit different data structure (different length). so, need able capture different sizes of data. doing far.
class program { static void main(string[] args) { tcpclient client = null; networkstream netstream = null; try { client = new tcpclient("192.168.1.xx", 00000); console.writeline("connected server..."); while (client.connected) { netstream = client.getstream(); //byte[] buffer = new byte[49]; //netstream.read(buffer, 0, 49); byte[] buffer = new byte[client.receivebuffersize]; netstream.read(buffer, 0, client.receivebuffersize); char[] chr= encoding.utf8.getchars(buffer); console.write(chr); } } catch (exception e) { console.writeline(e.message); } { netstream.close(); client.close(); } console.readline(); } }
the issue if use code.
byte[] buffer = new byte[client.receivebuffersize]; netstream.read(buffer, 0, client.receivebuffersize);
my buffer size 8192. causes data displayed have huge amount of blank space @ end.
if set size fixed size 49, data displayed correctly. since length of data may vary, cannot set 49.
what doing wrong?
any appreciated.
thanks.
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment