# eric6.Cooperation.Connection

Module implementing a class representing a peer connection.

### Global Attributes

MaxBufferSize
PingInterval
PongTimeout
SeparatorToken
TransferTimeout

### Classes

Connection | Class representing a peer connection.

### Functions

None

## Connection

Class representing a peer connection.

### Signals

editorCommand(hash, fn, message)
  emitted after an editor command has arrived (string, string, string)
getParticipants()
  emitted after a get participants message has arrived
newMessage(user, message)
  emitted after a new message has arrived (string, string)
participants(participants)
  emitted after the list of participants has arrived (list of strings of "host:port")
readyForUse()
  emitted when the connection is ready for use
rejected(message)
  emitted after a connection has been rejected (string)

### Derived from

QTcpSocket

### Class Attributes

Editor
GetParticipants
Greeting
Participants
Ping
PlainText
Pong
ProtocolEditor
ProtocolGetParticipants
ProtocolGreeting
ProtocolMessage
ProtocolParticipants
ProtocolPing
ProtocolPong
ReadingGreeting
ReadyForUse
Undefined
WaitingForGreeting

### Class Methods

None

### Methods

Connection | Constructor
__dataLengthForCurrentDataType | Private method to get the data length for the current data type.
__disconnected | Private slot to handle the connection being dropped.
__hasEnoughData | Private method to check, if enough data is available.
__processData | Private method to process the received data.
__processReadyRead | Private slot to handle the readyRead signal.
__readDataIntoBuffer | Private method to read some data into the buffer.
__readProtocolHeader | Private method to read the protocol header.
__sendGreetingMessage | Private slot to send a greeting message.
__sendPing | Private slot to send a ping message.
name | Public method to get the connection name.
sendEditorCommand | Public method to send an editor command.
sendGetParticipants | Public method to request a list of participants.
sendMessage | Public method to send a message.
sendParticipants | Public method to send the list of participants.
serverPort | Public method to get the server port.
setClient | Public method to set the reference to the cooperation client.
setGreetingMessage | Public method to set the greeting message.
timerEvent | Protected method to handle timer events.

### Static Methods

None

#### Connection (Constructor)

Connection(parent=None)

Constructor

parent
  referenec to the parent object (QObject)

#### Connection.__dataLengthForCurrentDataType

__dataLengthForCurrentDataType()

Private method to get the data length for the current data type.

Returns:
  data length (integer)

#### Connection.__disconnected

__disconnected()

Private slot to handle the connection being dropped.

#### Connection.__hasEnoughData

__hasEnoughData()

Private method to check, if enough data is available.

Returns:
  flag indicating availability of enough data (boolean)

#### Connection.__processData

__processData()

Private method to process the received data.

#### Connection.__processReadyRead

__processReadyRead()

Private slot to handle the readyRead signal.

#### Connection.__readDataIntoBuffer

__readDataIntoBuffer(maxSize=MaxBufferSize)

Private method to read some data into the buffer.

maxSize
  maximum size of data to read (integer)

Returns:
  size of data read (integer)

#### Connection.__readProtocolHeader

__readProtocolHeader()

Private method to read the protocol header.

Returns:
  flag indicating a successful read (boolean)

#### Connection.__sendGreetingMessage

__sendGreetingMessage()

Private slot to send a greeting message.

#### Connection.__sendPing

__sendPing()

Private slot to send a ping message.

#### Connection.name

name()

Public method to get the connection name.

Returns:
  connection name (string)

#### Connection.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)

#### Connection.sendGetParticipants

sendGetParticipants()

Public method to request a list of participants.

#### Connection.sendMessage

sendMessage(message)

Public method to send a message.

message
  message to be sent (string)

Returns:
  flag indicating a successful send (boolean)

#### Connection.sendParticipants

sendParticipants(participants)

Public method to send the list of participants.

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

#### Connection.serverPort

serverPort()

Public method to get the server port.

Returns:
  server port (integer)

#### Connection.setClient

setClient(client)

Public method to set the reference to the cooperation client.

client
  reference to the cooperation client (CooperationClient)

#### Connection.setGreetingMessage

setGreetingMessage(message, serverPort)

Public method to set the greeting message.

message
  greeting message (string)
serverPort
  port number to include in the message (integer)

#### Connection.timerEvent

timerEvent(evt)

Protected method to handle timer events.

evt
  reference to the timer event (QTimerEvent)

Up