Lost in setting up twisted for file transfer
up vote
0
down vote
favorite
After a few days of looking I have come to the conclusion that trying to setup a socket myself would be too complicated and unneeded as high-level modules are available such as Twisted
. However I'm having lots of trouble understanding it.
Sockets appeared pretty simple, First establish a connection and write to the connection.
Client side:
import socket
TransferSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
TransferSocket.connect(('localhost',5650))
fname = 'Hello world'
TransferSocket.send(fname.encode())
server side:
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversocket.bind(('localhost',5650))
serversocket.listen(1)
clientsock,clientAddress = serversocket.accept()
msg = clientsock.recv(1024).decode()
With Twisted however from the example I have found, I don't understand what is going on or how I can modify it to use.
client
from twisted.web.static import File
from twisted.web.resource import Resource
def resource():
resource = Resource()
resource.putChild(b"", File(u"c:testdogg.png"))
return resource
server
from twisted.python.filepath import FilePath
from twisted.internet.task import react
from treq import get, content
def main(reactor):
d = get(b"localhost:8080/")
d.addCallback(content)
d.addCallback(FilePath(u"c:tempimage.png").setContent)
return d
react(main, )
The end result is I want to transfer files that are 20-40mb in size from 1 computer to another across a local network. I found someone else had asked a similar question here however the answer was pointing to the documentation and it confuses me as many of the examples focus on websites and I'm having trouble following the code.
Am I supposed to use it like this?
client
from twisted.internet.protocol import Protocol
class Clientside():
def __init__(self):
self.Connection = Protocol.connectionMade()
self.Filename = 'c:testdog.png'
def sendata(self):
f = open(self.Filename,"rb")
chunk = f.read(1024)
while chunk:
Protocol.transport.write(chunk)
chunk = f.read(1024)
f.close()
server
????
python twisted
add a comment |
up vote
0
down vote
favorite
After a few days of looking I have come to the conclusion that trying to setup a socket myself would be too complicated and unneeded as high-level modules are available such as Twisted
. However I'm having lots of trouble understanding it.
Sockets appeared pretty simple, First establish a connection and write to the connection.
Client side:
import socket
TransferSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
TransferSocket.connect(('localhost',5650))
fname = 'Hello world'
TransferSocket.send(fname.encode())
server side:
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversocket.bind(('localhost',5650))
serversocket.listen(1)
clientsock,clientAddress = serversocket.accept()
msg = clientsock.recv(1024).decode()
With Twisted however from the example I have found, I don't understand what is going on or how I can modify it to use.
client
from twisted.web.static import File
from twisted.web.resource import Resource
def resource():
resource = Resource()
resource.putChild(b"", File(u"c:testdogg.png"))
return resource
server
from twisted.python.filepath import FilePath
from twisted.internet.task import react
from treq import get, content
def main(reactor):
d = get(b"localhost:8080/")
d.addCallback(content)
d.addCallback(FilePath(u"c:tempimage.png").setContent)
return d
react(main, )
The end result is I want to transfer files that are 20-40mb in size from 1 computer to another across a local network. I found someone else had asked a similar question here however the answer was pointing to the documentation and it confuses me as many of the examples focus on websites and I'm having trouble following the code.
Am I supposed to use it like this?
client
from twisted.internet.protocol import Protocol
class Clientside():
def __init__(self):
self.Connection = Protocol.connectionMade()
self.Filename = 'c:testdog.png'
def sendata(self):
f = open(self.Filename,"rb")
chunk = f.read(1024)
while chunk:
Protocol.transport.write(chunk)
chunk = f.read(1024)
f.close()
server
????
python twisted
Just a shot in the dark here butself.filename
andself.Filename
may not be the same thing
– Jamie_D
11 hours ago
Sorry, typo. But is this how the code works? Is this correct
– Hojo.Timberwolf
11 hours ago
There is a good example here
– Jamie_D
11 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
After a few days of looking I have come to the conclusion that trying to setup a socket myself would be too complicated and unneeded as high-level modules are available such as Twisted
. However I'm having lots of trouble understanding it.
Sockets appeared pretty simple, First establish a connection and write to the connection.
Client side:
import socket
TransferSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
TransferSocket.connect(('localhost',5650))
fname = 'Hello world'
TransferSocket.send(fname.encode())
server side:
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversocket.bind(('localhost',5650))
serversocket.listen(1)
clientsock,clientAddress = serversocket.accept()
msg = clientsock.recv(1024).decode()
With Twisted however from the example I have found, I don't understand what is going on or how I can modify it to use.
client
from twisted.web.static import File
from twisted.web.resource import Resource
def resource():
resource = Resource()
resource.putChild(b"", File(u"c:testdogg.png"))
return resource
server
from twisted.python.filepath import FilePath
from twisted.internet.task import react
from treq import get, content
def main(reactor):
d = get(b"localhost:8080/")
d.addCallback(content)
d.addCallback(FilePath(u"c:tempimage.png").setContent)
return d
react(main, )
The end result is I want to transfer files that are 20-40mb in size from 1 computer to another across a local network. I found someone else had asked a similar question here however the answer was pointing to the documentation and it confuses me as many of the examples focus on websites and I'm having trouble following the code.
Am I supposed to use it like this?
client
from twisted.internet.protocol import Protocol
class Clientside():
def __init__(self):
self.Connection = Protocol.connectionMade()
self.Filename = 'c:testdog.png'
def sendata(self):
f = open(self.Filename,"rb")
chunk = f.read(1024)
while chunk:
Protocol.transport.write(chunk)
chunk = f.read(1024)
f.close()
server
????
python twisted
After a few days of looking I have come to the conclusion that trying to setup a socket myself would be too complicated and unneeded as high-level modules are available such as Twisted
. However I'm having lots of trouble understanding it.
Sockets appeared pretty simple, First establish a connection and write to the connection.
Client side:
import socket
TransferSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
TransferSocket.connect(('localhost',5650))
fname = 'Hello world'
TransferSocket.send(fname.encode())
server side:
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversocket.bind(('localhost',5650))
serversocket.listen(1)
clientsock,clientAddress = serversocket.accept()
msg = clientsock.recv(1024).decode()
With Twisted however from the example I have found, I don't understand what is going on or how I can modify it to use.
client
from twisted.web.static import File
from twisted.web.resource import Resource
def resource():
resource = Resource()
resource.putChild(b"", File(u"c:testdogg.png"))
return resource
server
from twisted.python.filepath import FilePath
from twisted.internet.task import react
from treq import get, content
def main(reactor):
d = get(b"localhost:8080/")
d.addCallback(content)
d.addCallback(FilePath(u"c:tempimage.png").setContent)
return d
react(main, )
The end result is I want to transfer files that are 20-40mb in size from 1 computer to another across a local network. I found someone else had asked a similar question here however the answer was pointing to the documentation and it confuses me as many of the examples focus on websites and I'm having trouble following the code.
Am I supposed to use it like this?
client
from twisted.internet.protocol import Protocol
class Clientside():
def __init__(self):
self.Connection = Protocol.connectionMade()
self.Filename = 'c:testdog.png'
def sendata(self):
f = open(self.Filename,"rb")
chunk = f.read(1024)
while chunk:
Protocol.transport.write(chunk)
chunk = f.read(1024)
f.close()
server
????
python twisted
python twisted
edited 11 hours ago
asked 12 hours ago
Hojo.Timberwolf
369114
369114
Just a shot in the dark here butself.filename
andself.Filename
may not be the same thing
– Jamie_D
11 hours ago
Sorry, typo. But is this how the code works? Is this correct
– Hojo.Timberwolf
11 hours ago
There is a good example here
– Jamie_D
11 hours ago
add a comment |
Just a shot in the dark here butself.filename
andself.Filename
may not be the same thing
– Jamie_D
11 hours ago
Sorry, typo. But is this how the code works? Is this correct
– Hojo.Timberwolf
11 hours ago
There is a good example here
– Jamie_D
11 hours ago
Just a shot in the dark here but
self.filename
and self.Filename
may not be the same thing– Jamie_D
11 hours ago
Just a shot in the dark here but
self.filename
and self.Filename
may not be the same thing– Jamie_D
11 hours ago
Sorry, typo. But is this how the code works? Is this correct
– Hojo.Timberwolf
11 hours ago
Sorry, typo. But is this how the code works? Is this correct
– Hojo.Timberwolf
11 hours ago
There is a good example here
– Jamie_D
11 hours ago
There is a good example here
– Jamie_D
11 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371867%2flost-in-setting-up-twisted-for-file-transfer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Just a shot in the dark here but
self.filename
andself.Filename
may not be the same thing– Jamie_D
11 hours ago
Sorry, typo. But is this how the code works? Is this correct
– Hojo.Timberwolf
11 hours ago
There is a good example here
– Jamie_D
11 hours ago