This code won't run because of indents or something.
Help!
Code:
Help!
Code:
from System.Net.Sockets import *
from System.Text import *
class Module1(object):
def __init__(self):
self._clientsList = Hashtable()
def Main(self):
serverSocket = TcpListener(8888)
serverSocket.Start()
self.msg("Chat Server Started ....")
counter = 0
while (True):
counter += 1
clientSocket = serverSocket.AcceptTcpClient()
bytesFrom = Array.CreateInstance(Byte, 10024)
networkStream = clientSocket.GetStream()
networkStream.Read(bytesFrom, 0, clientSocket.ReceiveBufferSize)
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom)
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
self.clientsList(dataFromClient) = clientSocket
self.broadcast(dataFromClient + " Joined ", dataFromClient, False)
self.msg(dataFromClient + " Joined chat room ")
client = handleClinet()
client.startClient(clientSocket, dataFromClient, self._clientsList)
clientSocket.Close()
serverSocket.Stop()
self.msg("exit")
Console.ReadLine()
def msg(self, mesg):
mesg.Trim()
Console.WriteLine(" >> " + mesg)
def broadcast(self, msg, uName, flag):
enumerator = clientsList.GetEnumerator()
while enumerator.MoveNext():
Item = enumerator.Current
broadcastSocket = Item.Value
broadcastStream = broadcastSocket.GetStream()
if flag == True:
broadcastBytes = Encoding.ASCII.GetBytes(uName + " says : " + msg)
else:
broadcastBytes = Encoding.ASCII.GetBytes(msg)
broadcastStream.Write(broadcastBytes, 0, broadcastBytes.Length)
broadcastStream.Flush()
class handleClinet(object):
def __init__(self):
def startClient(self, inClientSocket, clineNo, cList):
self._clientSocket = inClientSocket
self._clNo = clineNo
self._clientsList = cList
ctThread.Start()
def doChat(self): #Dim infiniteCounter As Integer
bytesFrom = Array.CreateInstance(Byte, 10024)
requestCount = 0
while (True):
try:
requestCount = requestCount + 1
networkStream = self._clientSocket.GetStream()
networkStream.Read(bytesFrom, 0, self._clientSocket.ReceiveBufferSize)
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom)
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
self.msg("From client - " + self._clNo + " : " + dataFromClient)
rCount = Convert.ToString(requestCount)
self.broadcast(dataFromClient, self._clNo, True)
except Exception, ex:
self.MsgBox(ex.ToString)
finally: