-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
50 lines (43 loc) · 1.21 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Programming in Python
# Server.py
# Import the socket,sys and os library.
import sys
import socket
import os
ip:port
# Create a socket object
skServer = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# Bind to the port
# Default port for socket
# connect to the server on local computer
skServer.bind(("127.0.0.1",8889))
# Put the socket into listening mode
skServer.listen(10)
print "Server Active"
bFileFound = 0
# a forever loop until we interrupt it or
# an error occurs
while True:
# Establish connection with client.
Content,Address = skServer.accept()
print Address
sFileName = Content.recv(1024)
for file in os.listdir("/home/amit/Desktop/socket_program/123s.py"):
if file == sFileName:
print "in condition 1"
bFileFound = 1
break
if bFileFound == 0:
print sFileName+" Not Found On Server"
else:
print sFileName+" File Found"
fUploadFile = open(sFileName,"rb")
sRead = fUploadFile.read(1024)
while sRead:
Content.send(sRead)
sRead = fUploadFile.read(1024)
print "Sending Completed"
break
# Close the connection with the client
Content.close()
skServer.close()