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



????










share|improve this question
























  • 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










  • There is a good example here
    – Jamie_D
    11 hours ago















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



????










share|improve this question
























  • 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










  • There is a good example here
    – Jamie_D
    11 hours ago













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



????










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 11 hours ago

























asked 12 hours ago









Hojo.Timberwolf

369114




369114












  • 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










  • 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










  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]