tnetwork.h
上传用户:tigerk9
上传日期:2020-03-10
资源大小:237k
文件大小:2k
源码类别:

Telnet客户端

开发平台:

Visual C++

  1. // This is a simple class to handle socket connections
  2. // (Paul Brannan 6/15/98)
  3. #ifndef __TNETWORK_H
  4. #define __TNETWORK_H
  5. #include <windows.h>
  6. // Mingw32 doesn't use winsock.h (Paul Brannan 9/4/98)
  7. #ifdef __MINGW32__
  8. #ifdef __CYGWIN__
  9. #include <winsock.h>
  10. #else
  11. #include <Windows32/sockets.h>
  12. #endif
  13. #else
  14. #include <winsock.h>
  15. #endif
  16. enum NetworkType {TN_NETSOCKET, TN_NETPIPE};
  17. typedef int(*Naws_func_t)(char *, int, int);
  18. class TNetwork {
  19. private:
  20. SOCKET socket;
  21. BOOL local_echo; // Paul Brannan 8/25/98
  22. BOOL line_mode; // Paul Brannan 12/31/98
  23. NetworkType net_type; // Paul Brannan 3/18/99
  24. HANDLE pipeIn, pipeOut; // Paul Brannan 3/18/99
  25. Naws_func_t naws_func;
  26. char *local_address;
  27. public:
  28. TNetwork(SOCKET s = 0): socket(s), local_echo(1), line_mode(1),
  29. net_type(TN_NETSOCKET), naws_func((Naws_func_t)NULL),
  30. local_address((char *)NULL) {}
  31. ~TNetwork() {if(local_address) delete local_address;}
  32. void SetSocket(SOCKET s);
  33. SOCKET GetSocket() {return socket;}
  34. void SetPipe(HANDLE pIn, HANDLE pOut);
  35. void SetNawsFunc(Naws_func_t func) {naws_func = func;}
  36. void SetLocalAddress(char *buf);
  37. const char* GetLocalAddress() {return local_address;}
  38. NetworkType get_net_type() {return net_type;}
  39. int WriteString(const char *str, const int length);
  40. int ReadString (char *str, const int length);
  41. BOOL get_local_echo() {return local_echo;}
  42. void set_local_echo(BOOL b) {local_echo = b;}
  43. BOOL get_line_mode() {return line_mode;}
  44. void set_line_mode(BOOL b) {line_mode = b;}
  45. void do_naws(int width, int height);
  46. };
  47. #endif