Home Download Buy Blog Forum Support

Socket and sendall

Socket and sendall

Postby PhilippSchaffrath on Thu Dec 20, 2012 7:23 pm

Hi there,

currently i am trying to create a plugin, which provides a socketserver and sends to all connected clients some text if you hit a key-combination.

Here is what i got for now:
Code: Select all
import SocketServer, thread, sublime, sublime_plugin, pprint

HOST = "localhost"
PORT = 12321

class EchoRequestHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        while True:
            self.data = self.request.recv(1024)
            if not self.data:
            self.data = self.data.strip()

class socketapplication():
    def run(self):
        self.mythread = thread.start_new_thread(self.start, ())

    def start(self):
        self.server = SocketServer.TCPServer((HOST, PORT), EchoRequestHandler)

if 'app' in globals():

app = socketapplication()

class sendsomethingCommand(sublime_plugin.TextCommand):
    def run(self, edit):

As you can see, i am getting an instance of socketapplication and save it to the global variable app.
After that, i am calling the run method which creates a thread in which the socket gets created.

The Server works fine, i am able to connect and send data within the handle method of the EchoRequestHandler.

But within the sendsomethingCommand-run method, i want to tell the socket to send data to all of the clients.
Currently "app.server.socket.sendall("this-is-a-test")" throws an error like this:
Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
File ".\socketapplication.py", line 40, in run
File "<string>", line 1, in sendall

I hope you guys can help me sending data within the sendsomethingCommand class to all clients.

Kindly regards,
Posts: 17
Joined: Sat Mar 10, 2012 1:24 pm

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests