#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Location
    Alabama
    Posts
    30
    Rep Power
    11

    Dup2 a socket file discriptor over file file discriptor


    i am trying to read a file from across the network.

    Code:
     from socket import socket, AF_INET, SOCK_STREAM
    import os
    srvaddr = ('127.0.0.1', 11112)
    s = socket(AF_INET, SOCK_STREAM)
    s.connect(srvaddr)
    sockfd = s.fileno()
    while 1:
        data = raw_input("Send: ")
        os.write(sockfd, data + "\r\n")
        if data == "":
            break
    s.close()
    Code:
    from socket import socket, AF_INET, SOCK_STREAM
    import os
    file = open("test.txt", 'w')
    filefd = file.fileno()
    s = socket(AF_INET, SOCK_STREAM)
    sockfd =  s.fileno()
    s.bind(('127.0.0.1', 11112))
    s.listen(5)
    sock, addr = s.accept()
    while 1:
    
        while 1:
              dup2(filefd, sockfd
        sock.close()
        print "Connection closed"
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Well, what seems to be the problem?

    Just do what I do. Have the client send some sort of a request to the server, have the server respond with some form of an acceptance or denial depending on the IP of the client, have the client specify which file it needs, have the server read that file as binary and send 1024 bytes of the file at a time, meanwhile, the client will take in these bytes via the socket and write (as binary) to a new file.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    This seems to be the problem:

    Code:
    while 1:
    
        while 1:
              dup2(filefd, sockfd
    "Forever { forever { have a syntax error in a call to a function that doesn't exist. } }"

    Comments on this post

    • Grim Archon agrees : :D

IMN logo majestic logo threadwatch logo seochat tools logo