title: How can I send information from client side to server side using PIR-sensor [WinError 10057]
body: <p>We are two students working on a school project. The task is to connect a PIR-sensor (motion sensor) to a raspberry pi and whenever the sensor is detecting motion it should send a string to a text document on our AD/DNS server running Windows Server 2019. We are coding in Python and the code we use for the client (Raspberry Pi running the PIR-sensor) is using the following code:</p>
  
  <pre><code>import RPi.GPIO as GPIO
  import time
  import datetime
  import socket
  
  GPIO.setmode(GPIO.BCM)
  pir = 24
  
  GPIO.setup(pir, GPIO.IN)
  
  print ("Sensor initializing...")
  time.sleep(2)
  print ("active")
  print ("press ctrl+c to end program")
  
  mouvement = "Motion detected at "
  
  
  while True:
         if GPIO.input(pir) == True:
             now = datetime.datetime.now()
             fb = open("/home/pi/Projekt/pirsensor.txt", "a+")
             #print (mouvement)
             print(now.strftime("%Y-%m-%d %H:%M:%S "))
             fb.write(mouvement)
             fb.write(now.strftime("%Y-%m-%d %H:%M:%S "))
             fb.write("\n")
             fb.close()
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             s.connect(('192.168.1.3', 5007))
             s.send(mouvement)
             s.send(now.strftime ("%Y-%m-%d %H: %M: %S "))
             s.send("\n")
             s.close()
      #time.sleep(2)
  #time.sleep(0.1)         
  GPIO.cleanup()
  print (" program ended")
  </code></pre>
  
  <p>and the code we are using for the Windows Server 2019 is the following:</p>
  
  <pre><code>from socket import *
  port = 5007
  file = ''
  class Server:
      gate = socket(AF_INET, SOCK_STREAM)   
      host = '192.168.1.3'
      def __init__(self, port):
          self.port = port
          self.gate.bind((self.host, self.port))  
          self.listen()
  
      def listen(self):
          self.gate.listen(10)
          while True:
              print("Lyssnar på anslutningar, via port: ", self.port)
              add = self.gate.accept()
              self.reciveFileName()
              self.reciveFile()
  
  
      def reciveFileName(self):
          while True:
              data = self.gate.recv(1024)
              self.file = data
  
      def reciveFile(self):
          createFile = open("new_"+self.file, "wb")
          while True:
              data = self.gate.recv(1024)
              createFile.write(data)
          createFile.close()
  server= Server(port)
  listen()
  </code></pre>
  
  <p>Both devices are running on the same LAN network and have static IP-adresses. We are able to ping each other and able to send the information from the Raspberry pi with the PIR-sensor to the Windows Server 2019 machine. However, we have a problem. When we run the code on the Raspberry pi and wait for our server to recieve the data we get the following error: </p>
  
  <blockquote>
    <p>[WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/tduyf.png" rel="nofollow noreferrer">See image of the error</a></p>
  
  <p>We are stuck on this error and don't know how to fix it. We have been searching the web but we only find threads from 2006 and none of them are of any help. It's also worth noting that we have tried disabling the firewall. We also have no experience with coding in Python.</p>