java - C# Windows app read data from streamsocket not comprehensible -


i'm trying realize simple streamsocket-communication between server , client. server written in java , client in c#.

to send message (string) client server works fine. other way around have trouble.

when send string server client, want, every message printed out client.

i initialize streamsocket on client-side follows:

public async void startconn() {    streamsocket streamsocket = new streamsocket();    try      {        await streamsocket.connectasync(new windows.networking.hostname(server), port.tostring());         datareader reader = new datareader(streamsocket.inputstream);        reader.inputstreamoptions = inputstreamoptions.partial;        reader.unicodeencoding = windows.storage.streams.unicodeencoding.utf8;        var count = await reader.loadasync(256);         while (true)        {          string text = reader.readstring(count);                     debug.writeline("message: " + text);          count = await reader.loadasync(256);        }        }catch (exception e)      {        //todo      } } 

i want, client prints out every string server, how long message is. if send message server client, not print out every string although set option of streamsocket partial.

for example:

server send:   hello         client: print out nothing server send:   today         client: print out "hello" server send:   hi            client: print out nothing server send:   bye           client: print out "hi" 

i tried different versions of loadasync() size (not 256) , unconsumedbufferlength. everytime have same result. can tell me, what's wrong?

best regards djtrust

yes problem server-side. unbelievable, sure, java-code correct because side easy. concentrated on client-side.

my mistake follows:

... while(!(in.readline().equals("quit"))) {    string str = in.readline();    out.println(str);    out.flush(); } ... 

there 1 in.readline() much. correct way is:

string str = ""; while(!(str.equals("quit"))) {    str = in.readline();    out.println(str);    out.flush(); } 

i bite myself ;). hints.

djtrust


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -