Isotropix Forums

Socket communication using threading

Clarisse Scripting related topics

Socket communication using threading

Unread postby DoctorD » Sat May 18, 2019 10:11 am

Am using part of code from Clarisse Survival Kit to open a socket port. The problem is that when i run the script, its as if the code runs to a point and then halts, when i click on a menu item or do some action within Clarisse UI then code resumes execution but halts again. Shows the same behavior using the QThread class instead of threading. Am using 4.0 SP2b Build 4aaa6803a 2019-05-10 15:58:51 Clarisse iFX Personal Learning Edition on Windows 10. I am running the below code attached to shelf button.

Code: Select all
import json, sys, socket, time, threading, os
import socket
import re

host, port = '', 12359

class initialize_socket(threading.Thread):
    def __init__(self):

    def run(self):
        print "Starting up..."
            print "Making socket on port " + str(port)
            socket_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            socket_.bind((host, port))
            print "Socket bound"
            while True:
                client, addr = socket_.accept()
                data = ""
                buffer_size = 4096 * 2
                data = client.recv(buffer_size)
                if data != "":
                    self.TotalData = b""
                    self.TotalData += data
                    while True:
                        data = client.recv(4096 * 2)
                        if data:
                            self.TotalData += data


t = initialize_socket()
Posts: 1
Joined: Fri May 17, 2019 9:32 pm

Re: Socket communication using threading

Unread postby ayanik » Sun May 19, 2019 8:25 pm

Hi Doctor D,

I worked around it by spawning the process in a command prompt window. It will spawn a window running the listener outside of the Clarisse environment and will communicate via the Command Port when it gets data. With the Command Port you can run external Python code by passing it as a string.

I couldn't find another way to deal with it.
Posts: 88
Joined: Wed Nov 26, 2014 9:10 pm

Return to Scripting