Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. bool receive()
  2. {
  3. char buffer[1024];
  4. int inDataLength=recv(Socket,buffer,sizeof(buffer),0);
  5. if(buffer[0] != '')
  6. {
  7. std::cout<<"Client: ";
  8. std::cout << buffer;
  9. sendKey(string(buffer));
  10. }
  11. else if (inDataLength == 0) //Properly closed connection
  12. {
  13. std::cout<<"Connection lost..rn";
  14. return false;
  15. }
  16. return true;
  17. }
  18.  
  19. while ( receive() )
  20. {
  21. Sleep(1);
  22. }
  23.  
  24. public void send(String msg)
  25. {
  26. try {
  27. out.write( msg.getBytes("UTF8") );
  28. out.flush();
  29. Thread.sleep(100);
  30. } catch (SocketException e) {
  31. Global.error("Connection error..");
  32. //e.printStackTrace();
  33. } catch (UnsupportedEncodingException e) {
  34.  
  35. } catch (IOException e) {
  36. Global.error("Never connected..rn");
  37. } catch (Exception e)
  38. { Global.error("Sending failed..rn"); }
  39. }
  40.  
  41. int inDataLength=recv(Socket,buffer,sizeof(buffer),0);
  42. if (inDataLength == -1 ) {
  43. std::cerr << "receive error: " << GetLastError() << std::endl;
  44. return false;
  45. }
  46. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement