Python Forum
Python // C # - SOCKET connection is constantly interrupted
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python // C # - SOCKET connection is constantly interrupted
#1
Hello experts,


I'm new to the world of programming and I've already made a socket connection to C # on a Raspberry Pi (Python).

The software controls a servomotor. After a while, under the surface of the connection and the Raspberry Pi did not send commands to the servomotor because I believe the socket connection was broken.
Does anyone know a solution to my code?
import socket
from Handler import Handler
import time
from Servo import Servo
def Server(serverSocket, port):
    handler = Handler(12, 50)        
    serverSocket.listen(1)
    i=0
    connect = 1
    try:
        while i == 0:
            clientSocket, addr = serverSocket.accept()
            i = 1
        while connect == 1: 
            data = clientSocket.recv(1024)
            request = handler.handleRequest(data)
            if not data:
                  break
            if request == "SSDN K0":        
                connect = 0
            
    except Exception as ex: 
        print(ex)
    
    Server(serverSocket, port)
    
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
port=1234
serverSocket.bind(('192.168.0.8',port))
Server(serverSocket, port)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ssh tunnel connection dropped with Python achille 0 2,134 Jun-27-2021, 06:44 PM
Last Post: achille
  Clarification on how to set up non-blocking socket connection Shaggy 1 1,970 Oct-14-2020, 07:57 PM
Last Post: Skaperen
  python socket connect only sometimes espDino 0 1,524 Jul-15-2020, 12:13 PM
Last Post: espDino
  Python 2.7 vs Python 3.8 (Socket Module) MattB 8 6,604 Mar-18-2020, 01:02 PM
Last Post: MattB
  how to get your own ip using python (NO SOCKET:) ) julio2000 3 2,293 Mar-02-2020, 09:35 PM
Last Post: buran
  Python server(Django web site)/client(Python app) connection Junior_Pythoneer 5 3,797 Jul-05-2019, 05:41 PM
Last Post: noisefloor
  Multi connection socket server help! MuntyScruntfundle 0 2,711 Feb-19-2019, 12:03 PM
Last Post: MuntyScruntfundle
  For Xilinx EthernetLite LWIP:Need help in Python SOCKET Coding Saras 1 2,981 Oct-01-2018, 05:16 AM
Last Post: Saras
  Python Socket programming with packets sourabhjaiswal92 1 4,124 Sep-18-2018, 06:24 AM
Last Post: martingever
  Python socket : Error receive data quanglnh1993 1 13,011 Mar-14-2018, 11:59 AM
Last Post: avorane

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020