# eric7.Cooperation.CooperationClient

Module implementing the client of the cooperation package.

### Global Attributes

None

### Classes

CooperationClient | Class implementing the client of the cooperation package.

### Functions

None

## CooperationClient

Class implementing the client of the cooperation package.

### Signals

cannotConnect()
  emitted, if the initial connection fails
connectionError(message)
  emitted when a connection error occurs (string)
editorCommand(hash, filename, message)
  emitted when an editor command has been received (string, string, string)
newMessage(user, message)
  emitted after a new message has arrived (string, string)
newParticipant(nickname)
  emitted after a new participant joined (string)
participantLeft(nickname)
  emitted after a participant left (string)

### Derived from

QObject

### Class Attributes

None

### Class Methods

None

### Methods

CooperationClient | Constructor
__connectionError | Private slot to handle a connection error.
__connectionRejected | Private slot to handle the rejection of a connection.
__disconnected | Private slot to handle the disconnection of a chat client.
__findConnections | Private method to get a list of connection given a nick name.
__getParticipants | Private slot to handle the request for a list of participants.
__newConnection | Private slot to handle a new connection.
__processParticipants | Private slot to handle the receipt of a list of participants.
__readyForUse | Private slot to handle a connection getting ready for use.
banKickUser | Public method to ban and kick a user by its nick name.
banUser | Public method to ban a user by its nick name.
chatWidget | Public method to get a reference to the chat widget.
close | Public method to close all connections and stop listening.
connectToHost | Public method to connect to a host.
disconnectConnections | Public slot to disconnect from the chat network.
errorString | Public method to get a human readable error message about the last server error.
hasConnection | Public method to check for an existing connection.
hasConnections | Public method to check, if there are any connections established.
isListening | Public method to check, if the client is listening for connections.
kickUser | Public method to kick a user by its nick name.
nickName | Public method to get the nick name.
removeConnection | Public method to remove a connection.
sendEditorCommand | Public method to send an editor command.
sendMessage | Public method to send a message.
startListening | Public method to start listening for new connections.

### Static Methods

None

#### CooperationClient (Constructor)

CooperationClient(parent=None)

Constructor

parent
  reference to the parent object (QObject)

#### CooperationClient.__connectionError

__connectionError(socketError, connection)

Private slot to handle a connection error.

socketError (QAbstractSocket.SocketError)
  reference to the error object
connection (Connection)
  connection that caused the error

#### CooperationClient.__connectionRejected

__connectionRejected(msg)

Private slot to handle the rejection of a connection.

msg
  error message (string)

#### CooperationClient.__disconnected

__disconnected(connection)

Private slot to handle the disconnection of a chat client.

connection (Connection)
  connection that was disconnected

#### CooperationClient.__findConnections

__findConnections(nick)

Private method to get a list of connection given a nick name.

nick
  nick name in the format of self.nickName() (string)

Return:
  list of references to the connection objects (list of Connection)

#### CooperationClient.__getParticipants

__getParticipants(reqConnection)

Private slot to handle the request for a list of participants.

reqConnection (Connection)
  reference to the connection to get participants for

#### CooperationClient.__newConnection

__newConnection(connection)

Private slot to handle a new connection.

connection
  reference to the new connection (Connection)

#### CooperationClient.__processParticipants

__processParticipants(participants)

Private slot to handle the receipt of a list of participants.

participants
  list of participants (list of strings of "host:port")

#### CooperationClient.__readyForUse

__readyForUse(connection)

Private slot to handle a connection getting ready for use.

connection (Connection)
  connection that got ready for use

#### CooperationClient.banKickUser

banKickUser(nick)

Public method to ban and kick a user by its nick name.

nick
  nick name in the format of self.nickName() (string)

#### CooperationClient.banUser

banUser(nick)

Public method to ban a user by its nick name.

nick
  nick name in the format of self.nickName() (string)

#### CooperationClient.chatWidget

chatWidget()

Public method to get a reference to the chat widget.

Return:
  reference to the chat widget (ChatWidget)

#### CooperationClient.close

close()

Public method to close all connections and stop listening.

#### CooperationClient.connectToHost

connectToHost(host, port)

Public method to connect to a host.

host
  host to connect to (string)
port
  port to connect to (integer)

#### CooperationClient.disconnectConnections

disconnectConnections()

Public slot to disconnect from the chat network.

#### CooperationClient.errorString

errorString()

Public method to get a human readable error message about the last server error.

Return:
  human readable error message about the last server error (string)

#### CooperationClient.hasConnection

hasConnection(senderIp, senderPort=-1)

Public method to check for an existing connection.

senderIp
  address of the sender (QHostAddress)
senderPort
  port of the sender (integer)

Return:
  flag indicating an existing connection (boolean)

#### CooperationClient.hasConnections

hasConnections()

Public method to check, if there are any connections established.

Return:
  flag indicating the presence of connections (boolean)

#### CooperationClient.isListening

isListening()

Public method to check, if the client is listening for connections.

Return:
  flag indicating the listening state (boolean)

#### CooperationClient.kickUser

kickUser(nick)

Public method to kick a user by its nick name.

nick
  nick name in the format of self.nickName() (string)

#### CooperationClient.nickName

nickName()

Public method to get the nick name.

Return:
  nick name (string)

#### CooperationClient.removeConnection

removeConnection(connection)

Public method to remove a connection.

connection
  reference to the connection to be removed (Connection)

#### CooperationClient.sendEditorCommand

sendEditorCommand(projectHash, filename, message)

Public method to send an editor command.

projectHash
  hash of the project (string)
filename
  project relative universal file name of the sending editor (string)
message
  editor command to be sent (string)

#### CooperationClient.sendMessage

sendMessage(message)

Public method to send a message.

message
  message to be sent (string)

#### CooperationClient.startListening

startListening(port=-1)

Public method to start listening for new connections.

port
  port to listen on (integer)

Return:
  tuple giving a flag indicating success (boolean) and the port the server listens on

Up