473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Client server implementation

Hi everyone,

i wanted to implement a client- server connection
and transfer a file over the network. i was able to implement a normal
set up where in i was able to send chat messages and small chunks of
data.
I want to implement the file transfer with out using the FTP library
available in python .

So can anyone suggest a piece of code by which i can
do that.

Thanks
Pruthvi
Sep 15 '08 #1
4 3374
Babloo wrote:
Hi everyone,

i wanted to implement a client- server connection
and transfer a file over the network. i was able to implement a normal
set up where in i was able to send chat messages and small chunks of
data.
I want to implement the file transfer with out using the FTP library
available in python .

So can anyone suggest a piece of code by which i can
do that.

Thanks
Pruthvi
What Client OS? What Server OS? On LAN or Internet? You need to give is some
information to help you.

-Larry
Sep 15 '08 #2
On Sep 15, 5:15*am, Babloo <pruthviraj...@gmail.comwrote:
Hi everyone,

* * * * * * * * * i wanted to implement a client- server connection
and transfer a file over the network. i was able to implement a normal
set up where in i was able to send chat messages and small chunks of
data.
I want to implement the file transfer with out using the FTP library
available in python .

* * * * * * * * * So can anyone suggest a piece of codeby which i can
do that.
I don't know what you really want, but look at Twisted. http://twistedmatrix.com
>
Thanks
Pruthvi
Sep 16 '08 #3
On Sep 16, 7:38*am, Benjamin <musiccomposit...@gmail.comwrote:
On Sep 15, 5:15*am, Babloo <pruthviraj...@gmail.comwrote:
Hi everyone,
* * * * * * * * * i wanted to implement a client- server connection
and transfer a file over the network. i was able to implement a normal
set up where in i was able to send chat messages and small chunks of
data.
I want to implement the file transfer with out using the FTP library
available in python .
* * * * * * * * * So can anyone suggest a piece of code by which i can
do that.

I don't know what you really want, but look at Twisted.http://twistedmatrix.com
Thanks
Pruthvi

I am beginner at using python language.
I mean i am implementing that in a windows based machine and wanted
to transfer files over the LAN. I have written down two files as
client.py and server.py . I ran these files at two different Computers
in the LAN and I was able to send small chunks of messages( like
chat).

I was successful in establishing connection and sending small
messages. But now i want to transfer a complete file with out using
the ftplib(FTP LIBRARY) in python.
The files look like this.i hope this would help.

______________________________________________
# Server program

from socket import *

# Set the socket parameters
host = "117.105.224.94"
port = 21567
buf = 1024
addr = (host,port)

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)

# Receive messages
while 1:
data,addr = UDPSock.recvfrom(buf)
if not data:
print "Client has exited!"
break
else:
print "\nReceived message '", data,"'"

# Close socket
UDPSock.close()
__________________________________________________

# Client program

from socket import *

# Set the socket parameters
host = "117.105.224.94"
port = 21567
buf = 1024
addr = (host,port)

# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)

def_msg = "===Enter message to send to server===";
print "\n",def_msg

# Send messages
while (1):
data = raw_input('>')
if not data:
break
else:
if(UDPSock.sendto(data,addr)):
print "Sending message '",data,"'....."

# Close socket
UDPSock.close()

__________________________________________________ ___________

Sep 16 '08 #4
r0g
Babloo wrote:
On Sep 16, 7:38 am, Benjamin <musiccomposit...@gmail.comwrote:
>On Sep 15, 5:15 am, Babloo <pruthviraj...@gmail.comwrote:
>>Hi everyone,
i wanted to implement a client- server connection
and transfer a file over the network. i was able to implement a normal
set up where in i was able to send chat messages and small chunks of
data.
I want to implement the file transfer with out using the FTP library
available in python .
So can anyone suggest a piece of code by which i can
do that.
I don't know what you really want, but look at Twisted.http://twistedmatrix.com
>>Thanks
Pruthvi
I am beginner at using python language.
I mean i am implementing that in a windows based machine and wanted
to transfer files over the LAN. I have written down two files as
client.py and server.py . I ran these files at two different Computers
in the LAN and I was able to send small chunks of messages( like
chat).

I was successful in establishing connection and sending small
messages. But now i want to transfer a complete file with out using
the ftplib(FTP LIBRARY) in python.
The files look like this.i hope this would help.

______________________________________________
# Server program

from socket import *

# Set the socket parameters
host = "117.105.224.94"
port = 21567
buf = 1024
addr = (host,port)

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)

# Receive messages
while 1:
data,addr = UDPSock.recvfrom(buf)
if not data:
print "Client has exited!"
break
else:
print "\nReceived message '", data,"'"

# Close socket
UDPSock.close()
__________________________________________________

# Client program

from socket import *

# Set the socket parameters
host = "117.105.224.94"
port = 21567
buf = 1024
addr = (host,port)

# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)

def_msg = "===Enter message to send to server===";
print "\n",def_msg

# Send messages
while (1):
data = raw_input('>')
if not data:
break
else:
if(UDPSock.sendto(data,addr)):
print "Sending message '",data,"'....."

# Close socket
UDPSock.close()

__________________________________________________ ___________

You're really not far away then, you basically need to come up with a
simple protocol that can transmit

1) The file name
2) The file length
3) The file data itself

You could also transmit the files metadata: datestamps, permissions etc
if you wanted to make it better. Also, there might be security issues to
consider too if you're running this on anything other than your own home
network.

So anyway, for a simple solution howabout you send:

filename + "\n"
filesize + "\n" (make sure you use str() to send this as text)

Then loop through your filedata
send a chunk
wait for an OK back from the other side
loop

At the receiving end as the chunks arrive:

Get the filename
Open a file for writing
Get the filesize
Setup a loop to receive the file data
Send OK
Get chunk from socket
Write data to file
Break (stop) if filesize reached
Loop
Close file

This, of course has no error correction and will probably die if you
have any packet loss on your network, a more robust solution would be to
use TCP sockets rather than UDP sockets.

Hope this helps :-)
Roger Heathcote

http://www.technicalbloke.com
http://movingtoubuntu.technicalbloke.co.uk
Sep 17 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt | last post by:
I think this is the basic concept in ASP server-side development. My boss told me web application is NOT client-server application. I argued with him because browser is the client, and the server...
0
by: Ken Durden | last post by:
I'm working on a client-server application where the client is controlling two devices (aka servers) which both implement the same interface contract. We have a set of about 4 assemblies which...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
0
by: gg | last post by:
I'm currently trying to strengthen up the security on a large ASP.NET application (a web content management system). The primary objective is to prevent people from evesdropping for passwords and...
3
by: fred00 | last post by:
I have been searching for information relating to what I want to do, and I am assuming it is not a common issue. I have developed a web service and a client for a customer. I need to give the...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
4
by: Goh | last post by:
Hi, I would like to know how can we implement a web page that intelligent enough to unique identify that pc have been visit before without any cookies and login user require. I have try...
4
by: dynastar | last post by:
I'm trying to send custom COMExceptions from my C# server. My test client in C# has no problem reading the HRESULT I send (say, 0x80040002). Needless to say, the MFC client in C++ allows this...
1
by: Yogesh Chawla - PD | last post by:
Hello All, I work for the State of Wisconsin and we are trying to build a reference implementation using python. Our goals are this: 1) establish an HTTPS connection between our client and...
5
by: Ankur | last post by:
Hi Folks, I am new for this group. I want to clarify one thing what's a basic difference between Client Side Java Script and Server Side Java Script. how we can differentiate it. Why we called...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.