Thread: Opening a file and echoing the contents from it to the file descriptor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by purpleturtle_97 View Post
    Sorry I haven't been very clear here.

    EDIT:
    I have already created the socket in the main method, which basically results in:

    Code:
    int connection_sckt;
    connection_sckt = accept(list_s, NULL, NULL);
    
    //and then what I think should be...
    echoFile(connection_sckt, filename)
    //which would cop the contents of filename to the connection_sckt(if this is in fact the correct fd)
    You should post your whole code and let us look at it.

    Trust me... simply calling accept does not open a socket.
    And using fput() to echo characters to the socket handle does not send data.

    Here's an example of what it takes to open a listening socket in Winsock...
    Code:
    // initialize Client port/return port number
    WORD InitNetwork(WORD Port)
      { WSADATA     wsadata;              // winsock startup
        TCHAR       hn[MAX_HOSTNAME];     // host name
        DWORD       hs = MAX_HOSTNAME;    // host name size
        SOCKADDR    la;                   // local address
        WORD        lp = Port;            // local port
        // Load the Winsock DLL
        if (WSAStartup(MAKEWORD(2,0),&wsadata))
          return 0;
        // initialize local socket
        hSocket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
        if (hSocket == INVALID_SOCKET)
          return 0;
        // initialize localhost IP  
        GetComputerName(hn,&hs);
        if (!GetHostAddr(hn,Port,&la))
          return 0;
        // bind on user designated Port
        if (bind(hSocket,&la,sizeof(SOCKADDR)))
          return 0; 
        // start rx thread
        rxThread = CreateThread(NULL,0,&ReceiveDatagrams,NULL,0,0);
        return lp; }
    This is for UDP connections, TCP is a little different but no less complex.
    Last edited by CommonTater; 11-30-2011 at 12:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File descriptor file position
    By sethjackson in forum Linux Programming
    Replies: 3
    Last Post: 05-28-2008, 10:52 AM
  2. opening a file Descriptor
    By vin_pll in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2007, 05:03 AM
  3. How to read the file descriptor
    By vin_pll in forum C++ Programming
    Replies: 2
    Last Post: 11-26-2007, 01:58 AM
  4. why wrong file descriptor ??
    By alokdotnet in forum C Programming
    Replies: 2
    Last Post: 08-13-2006, 12:59 AM
  5. Echoing a File
    By 0rion in forum C++ Programming
    Replies: 2
    Last Post: 01-27-2006, 11:52 AM

Tags for this Thread