Skip to content

Matt-London/python-networking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Python Networking

This is a simple wrapper for the socket library. It boils down to send and receive rather than worrying about setup and byte counts

Importing

To import this module, make sure the networking package is in the current directory. Run the following either in a Python interpreter or in a Python program

>>> from networking.Server import Server # Import the server module (on the server)
>>> from networking.Client import Client # Import the client module (on the client)

Setting up the connection

Create both objects, likely on different computers Creating the server object on the server (ip, port):

>>> port = 4444 # Change this to desired port
>>> s = Server("127.0.0.1", port) # Open port 4444 on local loopback

Creating the client object (ip, port):

>>> ip = "192.168.1.12" # Change this to desired ip
>>> port = 4444 # Change this to desired port
>>> c = Client(ip, port)

Establishing the connection

On the server open the port first:

>>> s.bind()

NOTE: This will hang until a connection is made from a client


On the client, connect to the port:

>>> c.connect()

The TCP connection is now completed


Sending data

From either client or server: Use .send(str) to send information and .receive() to receive it

For example: On the server

>>> s.send("This is a test")

On the client

>>> c.receive()
'This is a test'

NOTE: .receive() will hang until data is received


Contributing

If you would like to contribute, you may make a pull request. It will be helpful if you first open an issue describing the change that you are interested in contributing.

License

MIT

About

High level networking objects using python socket

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages