mysocks package

Submodules

mysocks.Test_Server module

mysocks.file_send module

class mysocks.file_send.file_send(host='127.0.0.1', port=5560, n_listen=1)

Bases: mysocks.Model

This class is parent class to file transfer module.

accept_connections(filename)

mysocks.file_transfer module

class mysocks.file_transfer.file_transfer(host='127.0.0.1', port=5560, n_listen=1)

Bases: mysocks.Model

This class is parent class to file transfer module.

Parameters:
  • host (string, optional) – IP Address of the socket that the server will bind to. Defaults to localhost
  • port (int) – port of the socket server. Defaults to 5560
  • n_listen (int) – Max. number of clients to connect to at one time
Return s:

socket object

Rtype s:

socket object

accept_connections()
class mysocks.file_transfer.receive_files(save_path: str = '', host: str = '127.0.0.1', port: int = 5560)

Bases: mysocks.Model

This class is a parent class for all the procedures related to
receiving a file.
Parameters:
  • save_path (str) – path to save the received files.
  • host (str) – IP Address of the socket server
  • port (int) – port of the socket server. Defaults to 5560
receive_files()

Method to receive files from the socket server

class mysocks.file_transfer.send_files(filenames, host='127.0.0.1', port=5560, n_listen=1)

Bases: mysocks.Model

This class is a parent class for all file sending methods.
Call this class to send file_send
Parameters:
  • filenames (list) – List of filenames to send to the client
  • host (string) – IP Address of the socket that the server will bind to. Defaults to localhost
  • port (int) – port of the socket server. Defaults to 5560
  • n_listen (int) – Max. number of clients to connect to at one time
accept_connections()

Method to accept client connections

Returns:tuple of conn and addr of the connected client
Return type:tuple
lineno()
Returns the current line number in our program.
Used to find n=line number where the program is running during error handling
Returns:Integer referring the current line of program execution
Return type:int
send_files(filenames)

Method to send files to client.

Parameters:filenames – list of path of all the filenames to be sent over to the client. Paths can be absolute or relative.

mysocks.chat module

class mysocks.chat.chat(host='127.0.0.1', port=5660, n_listen=5)

Bases: mysocks.Model

This class is parent class to chat module

Parameters:
  • host (string, optional) – IP Address of the socket that the server will bind to. Defaults to 127.0.01
  • port (int) – port of the socket server. Defaults to 5660
  • n_listen (int) – Max. number of clients to connect to at one time. Defaults to 5
accept_connections()
class mysocks.chat.client(host='127.0.0.1', port=5660, **kwargs)

Bases: mysocks.Model

This class is a parent class for all text message client methods.
Call this class to start a chat client. This method connects to the server at the provided host and port
Parameters:
  • host (string, optional) – IP Address of the socket that the client will connect to. Defaults to 127.0.01
  • port (int) – port of the socket server. Defaults to 5660
gui_thread()

Method that will start a new thread to launch the gui when the function is called from terminal

receive_data()

Method to receive data from the server

send_data(**kwargs)

Method to send text messages to the server that will be relayed to other clients

set_username(**kwargs)

Method to set the username of the client

start_client(host, port)

Method to connect the client to the socket server and start sending and receiving messages.

class mysocks.chat.server(host='127.0.0.1', port=5660, n_listen=5, **kwargs)

Bases: mysocks.Model

This class is a parent class for all text message sending methods.
Call this class to start a chat server. CLients will be able to connect to this server and all the clients will be able to chat with each other. Server will not participate in the server.
Parameters:
  • host (string, optional) – IP Address of the socket that the server will bind to. Defaults to 127.0.01
  • port (int) – port of the socket server. Defaults to 5660
  • n_listen (int) – Max. number of clients to connect to at one time. Defaults to 5
Attr clients_connected:
 

Total number of clients connected till now including the ones which may have left in between the chat.

Attr all_connections:
 

socket object of all client connections. Deleted connections will be replaced by the keyword deleted.

Attr type all_names:
 

User names of all clients connected.

Attr type active_connections:
 

Total number of active clients connected to the chat server.

Attr s:

server socket object.

accept_connections()

Method to accept client connections. Creates a separate thread for each client to receive_data from clients

Returns:tuple of conn and addr of the connected client
Return type:tuple
gui_thread()

Method that will start a new thread to launch the gui when the function is called from terminal

receive_data(conn, addr, client_no)

Method to receive data from clients.

Parameters:
  • conn (socket object) – socket object of the client
  • addr (socket object) – Address of the socket object
  • client_no – Integer identifier of a client
start_server(host, port, n_listen)

Method to start socket server

Parameters:
  • host (string, optional) – IP Address of the socket that the server will bind to. Defaults to 127.0.01
  • port (int) – port of the socket server. Defaults to 5660
  • n_listen (int) – Max. number of clients to connect to at one time. Defaults to 5

mysocks.utilities module

mysocks.utilities.mapcount(filename)

Module contents

sockets module. Provides a library to create socket server and clients to chat or transfer files

class mysocks.Model

Bases: object

Base Model Class for mysocks package

host : string
IP Address of the socket that the server will bind to. Defaults to localhost
port : int
port of the socket server. Defaults to 5560
accept_connections()
create_client_socket(host, port)

Function to create a socket for a server that can handle n_listen number of clients at a time

Args:
host (string): IP address of the socket to be created on in decimal notation or in hexadecimal notation port (integer): Port number of the server that will be open for the clients
host : string
IP Address of the socket that the server will bind to. Defaults to localhost
port : int
port of the socket server. Defaults to 5560
s : socket object
socket object
create_server_socket(host, port, n_listen)

Function to create a socket for a server that can handle n_listen number of clients at a time

Args:
host (string): IP address of the socket to be created on in decimal notation or in hexadecimal notation port (integer): Port number of the server that will be open for the clients n_listen (integer): Maximum number of clients that the server can handle at a time
host : string
IP Address of the socket that the server will bind to. Defaults to localhost
port : int
port of the socket server. Defaults to 5560
n_listen : int
Max. number of clients to connect to at one time
s : socket object
socket object
file_transfer(src, dest)
host = ''
port = 5560