Kodi Community Forum

Full Version: How Do I Close A Clientsocket ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hey guys,

i've been looking in other scripts to hopefully get a few pointers on this but not getting anywhere fast

i was wondering if anyone knows how to close a socket (networking) connection through a scipt ? so far i've managed to find that the command to connect to another host is the following:

clientsocket.connect((hostname, port))

i havent been able to find anything though that tells me how to close it. would it be something like :

clientsocket.close?
clientsocket.disconnect?

so far i've tried these two but it doesn't appear to do anything. i assume this is the wrong syntax. any help would be really appreciated. . .thanx in advance. . .
it should be close
http://www.koders.com/python....60.aspx

or you could send a command to the server, so that the server closes the connection(this would require that the server inteprets a close command.).
like the xbmcdebugger script does.
http://www.xboxmediaplayer.de/cgi-bin....ebugger
Quote:#!/usr/bin/python
import sys
from socket import *

class dbg_client(object):

def (self, host, port):
self.serverhost = host
self.serverport = port
self.socket = socket(af_inet, sock_stream)
self.socket.connect((self.serverhost, int(self.serverport)))

def send_source(self, source):
self.socket.send('source' + source + '\n')

def ask_command(self):
self.socket.send('ask' + '\n')
data = self.socket.recv(1024)
return data

def close(self):
self.socket.send('close' + '\n')
self.socket.recv(1024)



thanks thor. that linked code has taught me a lot about python and what i'm currently trying. :d i've just started to learn the python language and it definately isn't my strong suit yet Smile prepare for more stupid questions to the forum as time goes on Smile