Skip to content

How to write an "Echo Server"? #568

@zsdz

Description

@zsdz

Sample 8 can enable the usbkeyboard,and echo the typed letter on screen

I want to write an "Echo Server",when user typed a line,the server will echo the while line,so I change the sample 8 code:

 void CKernel::KeyPressedHandler (const char *pString)
 {
     s_pThis->m_Screen.Write (pString, strlen (pString));

    if(pString[0]!='\n')
    {
	    strcat(s_pThis->s,pString);
    }
    else
    {
	    strcat(s_pThis->s,pString);
            s_pThis->m_Screen.Write (s_pThis->s, strlen (s_pThis->s));
	    strcpy(s_pThis->s,"");
    }
}

and add

strcpy(s_pThis->s,"");

in function

boolean CKernel::Initialize (void)

before

return bOK;

if got key not equal '\n',strcat it,else write it on screen and clear the buffer.

the prog works fine,but I write it in the call-back function KeyPressedHandler.I want write the logic in the "main function",in circle it should be the

TShutdownMode CKernel::Run (void)

function,like write

 scanf(line)
 printf(line)

in c,I can write it in the main function.After all I can't always put the logic code in the call-back function

How to do this?Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions