socket between c++ and java -


i wrote server in c++ , send messages set follow thread:

void *send(void* v) {     string m="";     while(true)     {         std::cin >> m;         write(socketfd, static_cast<void*>(&m), m.length()+1);     } } 

to read messages wrote follwing code:

public void recieve() throws ioexception{     while (true){         if(input.hasnext()){             viewtext.settext(viewtext.gettext() + "\nsever: "+input.nextline());         }     } }  @override public void run() {     try {         recieve();         socket.close();     }     catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();     } } 

when write variable m , press enter, nothing happen. when close server, values of m wrote before printed 1 string.

i apologize incorrect english. tnks

not knowing type of input in java code, method name nextline() suggests read whole line. line sequence of characters terminated newline character. on other hand, no newline character stored via std::cin >> m;, data until terminating sending side treated 1 line.

to send multiple lines, should use way such std::getline(std::cin, m); read input , add newline characters if way drops them.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -