# ---------------------------------------------------------------------------------------------------------------------- # Phase 1 Project, UDPClient.py # Written by Richard Douglas and Mounika Gannu # for 16.483/583.201 - Network Design: Principles, Protocols, and Applications at UMass Lowell # February 6, 2015 # # Credits to "Computer Networking, A Top Down Approach, 6th Ed." by Kurose and Ross for Python 2 code in Chapter 2, # as well as to Jeremy Plante for finding compatibility issues between Python 2 and Python 3 code. # ---------------------------------------------------------------------------------------------------------------------- from socket import * # this line allows the creation of sockets import sys serverName = 'localhost' serverPort = 12000 # communication will be on port 12000 clientSocket = socket(AF_INET, SOCK_DGRAM) buffer = 2048 print "Enter filename of image to send (Example: ImageTest.png) \n\n" filename = raw_input() fileOut = open(filename, 'rb') fileIn = open("Server" + filename, 'wb') while(1): data = fileOut(buffer) if not data: # if data in this variable is empty, aka if 0 data print "Finished sending file." break # break out of infinite loop #*clientSocket1.sendall(data) clientSocket.sendto(data, (serverName, serverPort)) while(1): modifiedData, serverAddress = clientSocket.recvfrom(2048) if not modifiedData: print "Finished receiving file." break fileIn = modifiedData(buffer) clientSocket.close()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question