Listener and Client Sockets/Remote Program Execution, etc.

This is a simple app to demonstrate listener and client Sockets/Remote program execution, and so on.

.


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.

Downloads

Demo and Source Code - 71 Kb



Comments

  • WwuKL dRg hOWk

    Posted by uvPkvxpchn on 11/14/2012 02:25pm

    buy soma online buy soma pills - buy soma double cross

    Reply
  • Why it can only work on local network but not internet

    Posted by ZJQ on 09/15/2007 06:47am

    It 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.

    Reply
  • Network by Internet

    Posted by Legacy on 12/20/2003 12:00am

    Originally 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

    Reply
  • Bug: Connect - Disconnect

    Posted by Legacy on 12/04/2003 12:00am

    Originally 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
    and made it "Listen". but it is not responding to any
    further clients.

    Reply
  • How can I use socket it in a DLL project?

    Posted by Legacy on 07/15/2003 12:00am

    Originally 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
    HPaitan

    Reply
  • Adding Listbox to Commander?

    Posted by Legacy on 02/17/2003 12:00am

    Originally 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?

    Reply
  • proxy

    Posted by Legacy on 01/23/2003 12:00am

    Originally posted by: Joan

    Is there any special consideration if any of the machines
    
    (client or server) is behind a proxy server??? For example,
    if my computer is served by a ADSL router with an static
    IP (so what you can see from inet is my router and not my
    machine).

    a newbie ;)

    Thanks.

    Reply
  • i saw these code about 1year ago

    Posted by Legacy on 01/22/2003 12:00am

    Originally posted by: dave.cliff

    r u a cheater?

    Reply
  • You can receive big file....

    Posted by Legacy on 07/30/2002 12:00am

    Originally posted by: davisHsu

    	m_ptrComSocket->Receive(&dwFlen, 4);	
    
    if(dwFlen == -1) return FALSE;
    gMem = GlobalAlloc(GHND, dwFlen);
    if(!gMem) {
    AfxMessageBox("Unable to alloc memory");
    return(FALSE);
    }
    byte* data;
    data = (byte*)GlobalLock(gMem);
    m_ptrComSocket->Receive(data, dwFlen);
    //-------------------------------------------------//
    try this modified

    int nBytesRead=m_ptrComSocket->Receive(&dwFlen, 4);

    if(dwFlen == -1) return FALSE;

    gMem = GlobalAlloc(GHND, dwFlen);
    if(!gMem) {
    AfxMessageBox("Unable to alloc memory");
    return(FALSE);
    }
    byte* data;
    data = (byte*)GlobalLock(gMem);

    // m_ptrComSocket->Receive(data, dwFlen);
    nBytesRead=0;
    while (dwFlen != nBytesRead) {
    int dataReadLen = m_ptrComSocket->Receive(data + nBytesRead, dwFlen - nBytesRead);
    nBytesRead += dataReadLen;
    };//end while

    //-----------------------------------------------------//
    Good luck!

    Reply
  • remotecontrol

    Posted by Legacy on 07/16/2002 12:00am

    Originally posted by: VanTri

    Is there a way to control clients from server?


    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Intelligent N+X Redundancy, Placement Affinities, & Future Proofing in the Virtualized Data Center Virtualization brought about the ability to simplify business continuity management in IT. Workload portability and data replication capabilities mean that physical infrastructure failures no longer need impact application services, and they can rapidly be recovered even in the event of complete site failure. However, Enterprises and Service Providers face new challenges ensuring they have enough compute …

  • Live Event Date: July 30, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. Check out this upcoming eSeminar that focuses on building an Android application using the MobileData service, with a walk-through of the real process and workflow used to build and link the MobileData service within your application. Join IBM's subject matter experts as they show you the way to build a base …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds