GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Aug-2006, 11:27
nugol nugol is offline
New Member
 
Join Date: Jul 2006
Posts: 3
nugol is on a distinguished road

Couple of Socket Questions


I am currently working on some socket programming, created a few programs but here is my question.

Info: Creating telnet server, attempting to add in client functions via the System(function) command

1) Is there a way to take a system function and send the results to the client, i.e.

the result of 'ps -aux' or 'tasklist' and send it to the client, i can currently have it first create a temporary file, then read the file to the client, is there a better way?

2) Does anyone have a link to a tutorial on unix/linux file sending programming? I cannot seem to find anything, unless I want to do with Windows. I take it isnt as easy as send(int, file, bitsize, int)

Thx for everything
  #2  
Old 26-Aug-2006, 13:03
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Couple of Socket Questions


Quote:
Originally Posted by nugol

1) Is there a way to take a system function and send the results to the client, i.e.

You might consider using a pipe. Here is an example that should work for Linux (gcc compiler):

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *inpipe;
    char inbuf[1000];

    int i;
    int inchar;
    /*char *command = "ls -l"; */
    char *command = "cat z.txt";

    inpipe = popen(command, "r");
    if (!inpipe) {
        printf("couldn't open pipe %s\n", command);
        return 0;
    }
    else {
        printf("Pipe <%s> opened for reading\n", command);
    }

    for (i = 0; i < sizeof(inbuf) - 1; i++) {
        inchar = fgetc(inpipe);
        if (inchar == EOF) {
            break;
        }
        inbuf[i] = inchar;
    }
    inbuf[i] = 0;
    printf("Number of chars read = %d\n", i);
    printf("inbuf: <%s>\n", inbuf);
    pclose(inpipe);

    return 0;
}
 

Here's the text file that I used:

Code:
Fourscore and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in liberty and dedicated to the proposition that all men are created equal.

Here's the output on my Fedora Core 5 platform:

Code:
Pipe <cat z.txt> opened for reading Number of chars read = 178 inbuf: <Fourscore and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in liberty and dedicated to the proposition that all men are created equal. >

Note that prototypes for popen() and pclose() are found in the GNU header <stdio.h>, and the functions are linked into my program automatically with the rest of the standard library, but the functions themselves are not part of the C (or C++) standard libraries.

Borland and Microsoft Windows compiler users can try pipes with _popen() and _pclose() instead of popen() and pclose().
Quote:
Originally Posted by nugol

2) Does anyone have a link to a tutorial on unix/linux file sending programming?

If by "file sending" you mean network programming (sockets programming), the answer is, "Yes, and it's a good one!"

Beej's Guide

Regards,

Dave
  #3  
Old 26-Aug-2006, 13:38
nugol nugol is offline
New Member
 
Join Date: Jul 2006
Posts: 3
nugol is on a distinguished road

Re: Couple of Socket Questions


Thank you for the very detailed help! It helped a lot and the link was awesome, thank you.
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[PROGRAM] Winsock Programming Max Payne MS Visual C++ / MFC Forum 1 09-Mar-2007 00:38
Socket Programming questions Radi0ShacK C++ Forum 4 14-Feb-2006 12:02
A couple questions about Fl_Tabs WW. FLTK Forum 3 07-Oct-2004 08:04
Couple of questions Memory and CD RW schuumi Computer Hardware Forum 3 15-Sep-2004 16:32
Multi-Lingual Webpages & A Couple General Questions. dwaunthomas Web Design Forum 5 15-May-2004 12:07

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:00.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.