Listener and Client Sockets/Remote Program Execution, etc.
SockListener GUI
SockCommander GUI
Environment: VC6, NT4, Win9x
Hi Friends,
First of all, let me thank all the contributors to codeguru.com; your knowledge and expertise has helped me tremendously. You will see I'm using many code snippets from them in many of my applications.
I'm submitting this simple and very basic CSocket program due to the large number of requests I receive almost every day from the codeguru VC++ discussion board. Experienced programmers will find this simple and easy to develop, but I guess the beginners will get a good introduction to CSockets and its raw power.
There are two applications I'm submitting here: SockCommander (SC) and SockListener (SL). SL acts as the server and listens on port 777. This application must be run on that PC which you intend to control (well... in a way). Take down the IP address shown there and then execute SC on that PC from where you intend to control the server. Enter the IP address you got from the server in the relevant edit box in SC and press Connect. If successful, a message will be displayed both on SC and SL, saying 'Connected'. Now to the interesting part. You can now send commands/messages to the server from now onwards by just entering the command on the Command/Msg edit box and pressing the Send button.
At the moment commands available for SockCommander are:
| Command | Description |
| CMD: <your command> | Sends a command thats to be executed at SockListener e.g CMD:Notepad.Exe will execute notepad at SL |
| FILEGET: <path of file to retrieve> | Retrieves small files from SL. This is still under test stage, not to be used for big files. e.g FILEGET:c:\msdos.sys (don't forget to enter a valid filepath in the File Save as edit box) |
| !SHUT | Shuts down SL |
The possibilities of these apps are tremendous in the hands of a creative/thinking programmer!
All the best and Happy coding.

Comments
WwuKL dRg hOWk
Posted by uvPkvxpchn on 11/14/2012 02:25pmbuy soma online buy soma pills - buy soma double cross
ReplyWhy it can only work on local network but not internet
Posted by ZJQ on 09/15/2007 06:47amIt works on 2 PC inside a local network. But I don't know why it can't work between 2 PC with Window-XP sp2. I close the firewall.
ReplyNetwork by Internet
Posted by Legacy on 12/20/2003 12:00amOriginally posted by: Wessels
If am connected to the internet and start the programm SockListener the text in the border is 'Server 192.168.0.1' and not the IP-adress of my computer in the running internet-connection. 'Server 192.168.0.1' is the adress of my computer in the LAN.
What I have to do ?
The computer is running with Windows XP Prefessional.
Michael
ReplyBug: Connect - Disconnect
Posted by Legacy on 12/04/2003 12:00amOriginally posted by: V.Srinivas
M.Wittmann has rectified client code
by not making client have fixed port.
This works well.
I have another problem:
I changed the code, kept a "listen" & "Restart" buttons
in the server.
I have also created server socket object dynamically.
when i press restart i closed the current object, and
deallocated memory.
but, when i again create the server object dynamically
Replyand made it "Listen". but it is not responding to any
further clients.
How can I use socket it in a DLL project?
Posted by Legacy on 07/15/2003 12:00amOriginally posted by: H.Paitan
Hi,
I'm learning VC++ and I need make a DLL using Sockets in order to connect an Application server with a client, but the client should be coded in a DLL.
thanks
ReplyHPaitan
Adding Listbox to Commander?
Posted by Legacy on 02/17/2003 12:00amOriginally posted by: Devin
This was a great demo, but I've run across a strange problem.
In trying to facilitate bi-directional messaging, I overloaded OnReceive in the CCommandSocket class to read:
void CCommandSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CSocket::OnReceive(nErrorCode);
m_ptrDlg->ProcessPendingRead(this);
}
Then created a method in the CSockCommanderDlg class as such...
void CSockCommanderDlg::ProcessPendingRead(CCommandSocket *pSocket)
{
char *lpBuf;
lpBuf = new char [1000];
for(int i=0;i<1000;i++){
*(lpBuf+i) = 0;
}
pSocket->Receive( lpBuf, 1000);
m_Msglist.InsertString(-1,lpBuf);
AfxMessageBox(lpBuf);
delete [] lpBuf;
}
Things worked great when I just had the message popping up with a call to "AfxMessageBox", but when I tried adding it to a listbox using "CListBox::InsertString", I get Unhandled Exception 0xC0000005: Access Violation...
If I add a string to the same listbox member variable from a different method in the same class, there's no problem, and this is almost identical to what is being done in the Listener App with no problems; I'm stumped. Am I doing something wrong, or is this a bug?
Replyproxy
Posted by Legacy on 01/23/2003 12:00amOriginally posted by: Joan
Replyi saw these code about 1year ago
Posted by Legacy on 01/22/2003 12:00amOriginally posted by: dave.cliff
r u a cheater?
Reply
You can receive big file....
Posted by Legacy on 07/30/2002 12:00amOriginally posted by: davisHsu
Replyremotecontrol
Posted by Legacy on 07/16/2002 12:00amOriginally posted by: VanTri
Is there a way to control clients from server?
ReplyLoading, Please Wait ...