winsock chat

This is a discussion on winsock chat within the Networking/Device Communication forums, part of the General Programming Boards category; Code: bool keyHit(void) { /* Get a handle to console input buffer */ HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE); /* Save the ...

  1. #16
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    bool keyHit(void)
    {
      /* Get a handle to console input buffer */
      HANDLE  stdIn = GetStdHandle(STD_INPUT_HANDLE);
    
      /* Save the console mode so we can restore it later */
      DWORD   saveMode;
      GetConsoleMode(stdIn, &saveMode);
    
      /* Set the console mode. The primary purpose of this is
       * to make sure ENABLE_LINE_INPUT is disabled. As its name 
       * suggests ENABLE_LINE_INPUT will not return until the end of
       * the line while we are interested in individual characters. */ 
      SetConsoleMode(stdIn, ENABLE_PROCESSED_INPUT);
    
      bool  ret = false;
    
      /* This waits 1 millisecond for the input buffer to be signalled
       * The input buffer enters the signalled state when one or more characters
       * are available. If the input buffer is signalled WaitForSingleObject()
       * will return WAIT_OBJECT_0 and we set ret to true to indicate that there
       * is character(s) in the input buffer. If the input buffer does not become
       * signalled in the timeout period it will return WAIT_TIMEOUT. */
      if (WaitForSingleObject(stdIn, 1) == WAIT_OBJECT_0) ret = true;
    
      /* We restore the console mode that we saved at the start of the function. */
      SetConsoleMode(stdIn, saveMode);
    
      /* We return the value of ret */
      return(ret);
    }
    getChar() is very similar, except that it uses ReadConsole() to actually read a character from the console input buffer.

  2. #17
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > and i never put code in my programs that i dont understand..
    Highlight functions you don't know about and press F1
    We're not going to spoon-feed the whole program for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #18
    Registered User
    Join Date
    Apr 2004
    Posts
    102
    i cant press f1, i dont have msdn installed

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 07:32 AM
  2. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 11:11 AM
  3. Requesting Java Chat Client Maintenence
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-02-2003, 12:57 PM
  4. SO close to finishing chat program...!
    By Nakeerb in forum C++ Programming
    Replies: 13
    Last Post: 10-26-2002, 12:24 PM
  5. Rough Portable Chat Design Sketch
    By ggs in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-27-2001, 07:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21