title: Python 3: Sending files through socket. (Client-Server Program)
body: <p>I am having the above issue. The client is suppose to ask for a filename and send the file name to the server after which the server will open the file and display it. Problem is that the server isn't opening the file and displaying it. </p>
  
  <p>Below is the client.</p>
  
  <pre><code>#!/usr/bin/env python3 
  import socket, os.path, datetime, sys
  
  def Main():
      host = '127.0.0.1'
      port = 50001
  
      s = socket.socket()
      s.connect((host, port))
  
      Filename = input("Type in ur file ")
      s.send(Filename.encode('utf-8'))
      data = s.recv(1024).decode('utf-8')
      s.close()
  
  if __name__ == '__main__':
      Main()
  </code></pre>
  
  <p>Below is the server</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import socket
  import os
  import sys
  
  
  
  def Main():
      host = '127.0.0.1'
      port = 50001
  
      s = socket.socket()
      s.bind((host,port))
      print("server Started")
      s.listen(1)
      c, addr = s.accept()
      print("Connection from: " + str(addr))
      while True:
          data = c.recv(1024).decode('utf-8')
          myfile = open(data, "r")
          if not data:
              break
          print("from connected user: " + myfile)
  
      c.close()
  
  if __name__ == '__main__':
      Main()
  </code></pre>