topical media & game development

talk show tell print

server-echo.c

? / server-echo.c


  include <hush/source.h>
  include <hush/iostream.h>
  include "socket/socket.h"
  include <process.h>
  include <string>
  
  unsigned __stdcall Answer(void* a) {
    Socket* s = (Socket*) a;
  
    while (1) {
      std::string r = s->ReceiveLine();
      if (r.empty()) break;
      cerr << r << endl;
      std::string q = (char*) "answer: "; 
      s->SendLine(q);
      s->SendLine(r);
    }
  
    delete s;
  
    return 0;
  }
  
  int main(int argc, char* argv[]) {
    SocketServer in(1234,5);
  
    while (1) {
      Socket* s=in.Accept();
  
      unsigned ret;
      _beginthreadex(0,0,Answer,(void*) s,0,&ret);
    }
   
    return 0;
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.