Click here to Skip to main content
15,886,063 members
Articles / Desktop Programming / MFC

Telnet Console Application

Rate me:
Please Sign up or sign in to vote.
4.96/5 (18 votes)
31 Jul 2001 278.7K   9.3K   63  
A console based telnet application.
// SocketTx.cpp: implementation of the CSocketTx class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Telnet.h"
#include "conio.h"
#include "SocketTx.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern HANDLE stdin1;
extern HANDLE stdout1;
extern HANDLE stderr1;

CSocketTx::CSocketTx(SOCKET hSocket,HANDLE &hThread)
{
DWORD dwRet;

	m_nExit = 0;
	m_hThread = NULL;
	m_hSocket = hSocket;

	m_hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) SendTh,(LPVOID)this,0,&dwRet);
	if ( m_hThread == NULL ) return;
	hThread = m_hThread;
}
CSocketTx::~CSocketTx()
{
	m_nExit = 1;
}
DWORD CSocketTx::SendTh(CSocketTx *pSocketTx)
{
char pBuff[256];
unsigned long dwLen;
int nRet;
char ch;

	dwLen = 1;
	while(1)
	{
		if ( pSocketTx->m_nExit == 1 ) { ExitThread(0); return 0; }
		WaitForSingleObject(stdin1,INFINITE);
		ch = getch();
		nRet = send(pSocketTx->m_hSocket,&ch,dwLen,0);
		if ( nRet == SOCKET_ERROR ) { TRACE("\nSend Fail........!\n"); pSocketTx->m_nExit = 0; continue;}
	}
  return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Pakistan Pakistan
Master of Computer Science
Experince
1). C++
2). C
3). Network Programming...
Socket,Pipe,Protocol Implemntation
4). hardware interfaceing
5). Emabeded programming in C51...Etc
(for 8051,PIC,C166 Processores)


Comments and Discussions