Name | socket-kit JSON |
Version |
0.2.1
JSON |
| download |
home_page | |
Summary | A utility with concise and more fluent code in socket programming |
upload_time | 2023-12-25 08:21:29 |
maintainer | |
docs_url | None |
author | Yiming Liu |
requires_python | |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# socket-kit
`socket-kit` is a utility with concise and more fluent code in socket programming. It handles the job of creating server/client, database operations, transferring data and file over network, as well as OpenCV support.
## Server and Client
```python
from socket_kit import socket_kit
server = createServer("192.168.31.138", 9990, clientNum=3)
server = createdLocalhostServer(9990, clientNum=3)
server = createdLocalIPServer(9990, clientNum=3)
client = createClient("192.168.31.138", 9990)
```
## Database
### Database Side
```python
from socket_kit import socket_kit
database = socket_kit.MySQLDatabase("database_name", host="localhost" username="root", password="password")
database.createTable("table_name", """
id INTEGER PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL
""")
database.createUserTabel()
database.createUser("username", "password")
# create user with token is actually normal create user
# username = "_token_"
token = socket_kit.randomToken()
database.createUserWithToken(token)
```
### Server Side
```python
from socket_kit import socket_kit
if socket_kit.userAuthenticate(client, database):
print("Connected with", address)
else: continue
```
### Client Side
```python
from socket_kit import socket_kit
socket_kit.userLogin(client, "username", "password")
socket_kit.userLoginWithToken(client, "token")
# login in CLI
socket_kit.userLoginCLI(client)
```
## Data Transfer
To concentrate on data transfer, the code below will ignore the concept of server/client, because the sender/receiver can appear at both depending on your requirement.
### Sender
```python
from socket_kit import socket_kit
# send pure data
data = b""
message = socket_kit.packData(data)
client.sendall(message)
# send file
message = socket_kit.packFile("movieFile.mp4")
client.sendall(message)
# send frame (OpenCV)
message = socket_cv.packFrame(frame)
client.sendall(message)
```
### Receiver
```python
from socket_kit import socket_kit
# receive pure data
data = socket_kit.receiveData(client)
# receive file
socket_kit.receiveFile("savedFile.mp4", client)
# receive frame (OpenCV)
frame = socket_kit.receiveFrame(client)
```
### Stream Receiver
```python
message = b""
while True:
# receive stream pure data
data, message = socket_kit.receiveStreamData(message, client)
# receive stream frame (OpenCV)
frame, message = socket_kit.receiveStreamFrame(message, client)
```
## OpenCV
```python
from socket_kit import socket_kit
capture = socket_kit.createCapture()
# default .mp4 with Codec H264
writer = socket_kit.createWriter(capture, "saveMovie.mp4")
socket_kit.saveFrameToMovie(frame, writer)
socket_kit.saveFrameToPhoto(frame, "saveMovie.png")
socket_kit.showFrame("frame", frame)
```
Raw data
{
"_id": null,
"home_page": "",
"name": "socket-kit",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Yiming Liu",
"author_email": "YimingDesigner@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/0a/15/e30eae52aac4c7f3df1c6ef81949e4a83b1d6593c3b30c94e6de5e0256cb/socket_kit-0.2.1.tar.gz",
"platform": null,
"description": "# socket-kit\n\n`socket-kit` is a utility with concise and more fluent code in socket programming. It handles the job of creating server/client, database operations, transferring data and file over network, as well as OpenCV support.\n\n## Server and Client\n\n```python\nfrom socket_kit import socket_kit\n\nserver = createServer(\"192.168.31.138\", 9990, clientNum=3)\nserver = createdLocalhostServer(9990, clientNum=3)\nserver = createdLocalIPServer(9990, clientNum=3)\nclient = createClient(\"192.168.31.138\", 9990)\n```\n\n## Database\n\n### Database Side\n\n```python\nfrom socket_kit import socket_kit\n\ndatabase = socket_kit.MySQLDatabase(\"database_name\", host=\"localhost\" username=\"root\", password=\"password\")\n\ndatabase.createTable(\"table_name\", \"\"\"\n id INTEGER PRIMARY KEY AUTO_INCREMENT,\n username VARCHAR(255) NOT NULL,\n password VARCHAR(255) NOT NULL\n\"\"\")\n\ndatabase.createUserTabel()\ndatabase.createUser(\"username\", \"password\")\n# create user with token is actually normal create user\n# username = \"_token_\"\ntoken = socket_kit.randomToken()\ndatabase.createUserWithToken(token)\n```\n\n### Server Side\n\n```python\nfrom socket_kit import socket_kit\n\nif socket_kit.userAuthenticate(client, database):\n print(\"Connected with\", address)\nelse: continue\n```\n\n### Client Side\n\n```python\nfrom socket_kit import socket_kit\n\nsocket_kit.userLogin(client, \"username\", \"password\")\nsocket_kit.userLoginWithToken(client, \"token\")\n# login in CLI\nsocket_kit.userLoginCLI(client)\n```\n\n## Data Transfer\n\nTo concentrate on data transfer, the code below will ignore the concept of server/client, because the sender/receiver can appear at both depending on your requirement.\n\n### Sender\n\n```python\nfrom socket_kit import socket_kit\n\n# send pure data\ndata = b\"\"\nmessage = socket_kit.packData(data)\nclient.sendall(message)\n\n# send file\nmessage = socket_kit.packFile(\"movieFile.mp4\")\nclient.sendall(message)\n\n# send frame (OpenCV)\nmessage = socket_cv.packFrame(frame)\nclient.sendall(message)\n```\n\n### Receiver\n\n```python\nfrom socket_kit import socket_kit\n\n# receive pure data\ndata = socket_kit.receiveData(client)\n\n# receive file\nsocket_kit.receiveFile(\"savedFile.mp4\", client)\n\n# receive frame (OpenCV)\nframe = socket_kit.receiveFrame(client)\n```\n\n### Stream Receiver\n\n```python\nmessage = b\"\"\nwhile True:\n # receive stream pure data\n data, message = socket_kit.receiveStreamData(message, client)\n # receive stream frame (OpenCV)\n frame, message = socket_kit.receiveStreamFrame(message, client)\n```\n\n## OpenCV\n\n```python\nfrom socket_kit import socket_kit\n\ncapture = socket_kit.createCapture()\n\n# default .mp4 with Codec H264\nwriter = socket_kit.createWriter(capture, \"saveMovie.mp4\")\nsocket_kit.saveFrameToMovie(frame, writer)\n\nsocket_kit.saveFrameToPhoto(frame, \"saveMovie.png\")\n\nsocket_kit.showFrame(\"frame\", frame)\n```\n\n",
"bugtrack_url": null,
"license": "",
"summary": "A utility with concise and more fluent code in socket programming",
"version": "0.2.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4a01d59e6270a10cd6b300cf6355e9a452a896fb8e49c4d3d9bab59e006dfc78",
"md5": "0fe37986a32b225e5f0162bd86801fa7",
"sha256": "bcb6200f7aa371d274a0ccff266c2db55f799e6eca4932659e24ad959c7df3fb"
},
"downloads": -1,
"filename": "socket_kit-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0fe37986a32b225e5f0162bd86801fa7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5597,
"upload_time": "2023-12-25T08:21:28",
"upload_time_iso_8601": "2023-12-25T08:21:28.165242Z",
"url": "https://files.pythonhosted.org/packages/4a/01/d59e6270a10cd6b300cf6355e9a452a896fb8e49c4d3d9bab59e006dfc78/socket_kit-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0a15e30eae52aac4c7f3df1c6ef81949e4a83b1d6593c3b30c94e6de5e0256cb",
"md5": "ace1f2633253e1e504fbdb9c3072d6cc",
"sha256": "7b77e24c389fb17de8c508fec342bbfa2ec28fea3087c6d0f3fb51eccea7e8c4"
},
"downloads": -1,
"filename": "socket_kit-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "ace1f2633253e1e504fbdb9c3072d6cc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5092,
"upload_time": "2023-12-25T08:21:29",
"upload_time_iso_8601": "2023-12-25T08:21:29.690302Z",
"url": "https://files.pythonhosted.org/packages/0a/15/e30eae52aac4c7f3df1c6ef81949e4a83b1d6593c3b30c94e6de5e0256cb/socket_kit-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-25 08:21:29",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "socket-kit"
}