Giter Site home page Giter Site logo

jsonsocket's Introduction

jsonsocket

This is a small Python library for sending data over sockets.

It allows sending lists, dictionaries, strings, etc. It can handle very large data (I've tested it with 10GB of data). Any JSON-serializable data is accepted.

Examples:

from jsonsocket import Client, Server

host = 'localhost'
port = '8000'

# Client code:
client = Client()
client.connect(host, port).send({'some_list': [123, 456]})
response = client.recv()
# response now is {'data': {'some_list': [123, 456]}}
client.close()


# Server code:
server = Server(host, port)
server.accept()
data = server.recv()
# data now is: {'some_list': [123, 456]}
server.send({'data': data}).close()

jsonsocket's People

Contributors

mdebbar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonsocket's Issues

no ssl support...

I need ssl support to all commit it when I add it for myself... I was thinking of adding some kind of UNIX socket connect attempt if on talking over localhost... to speedup to and secure...
also it would be cool if someone made a node js library that would talk effortlessly to this aswell... The amount of power behind such a framework... open source and all :) you'll see my dinglehopper soon.

Test script does not run well

Tried to run example script on python 3.6 Win 10 x64 and met next error:

Traceback (most recent call last):

  File "<ipython-input-2-4804133fcaae>", line 1, in <module>
    runfile('C:/Users/user/Desktop/json_test.py', wdir='C:/Users/user/Desktop')

  File "C:\anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)

  File "C:\anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/user/Desktop/json_test.py", line 1, in <module>
    from jsonsocket import Client, Server

  File "<frozen importlib._bootstrap>", line 961, in _find_and_load

  File "<frozen importlib._bootstrap>", line 946, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 881, in _find_spec

  File "<frozen importlib._bootstrap>", line 855, in _find_spec_legacy

  File "C:\anaconda\lib\site-packages\pyximport\pyximport.py", line 253, in find_module
    fp, pathname, (ext,mode,ty) = imp.find_module(fullname,package_path)

  File "C:\anaconda\lib\imp.py", line 270, in find_module
    "not {}".format(type(path)))

RuntimeError: 'path' must be None or a list, not <class '_frozen_importlib_external._NamespacePath'>

Only single client

Do I interpret this correctly that you are effectively allowing only a single client to connect? Even though the maximum amount of connections is set to 5 in the call to listen an established connection is dropped as soon as a new connection request is issued.

multithreading server

Hello,

thanks for this pgm.
I have an issue with spawning server threads using the class Server. e.g., in a case like:

while True:
    server.accept()  
    ct=sThread(server.client)
    ct.run()

I guess that optimally we would like server.client to be able to send JSON over TCP in the optimal way afforded by the class Server. But...
It seems to me that server.client is, because of the definition of Server.accept(), an instance of the regular socket class. That is, it is not an instance of your improved for JSON socket class, not an instance of Server.accept(). Am I right?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.