Giter Site home page Giter Site logo

ksenginew / wsocket Goto Github PK

View Code? Open in Web Editor NEW
25.0 4.0 3.0 161 KB

Simple WSGI HTTP + Websocket Server, Framework, Middleware And App.

Home Page: https://wsocket.gitbook.io/

License: MIT License

HTML 3.93% Python 96.07%
http websocket python single-file wsgi wsgiref wsocket middleware handler app

wsocket's Introduction

wsocket's People

Contributors

ksengine avatar ksenginew 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

Watchers

 avatar  avatar  avatar  avatar

wsocket's Issues

no docs

add docs link to readme, pypi and github header
add bug tracker link to them.

Need Contributors

Note:
I am a student.I have no enough knowladge. So can anyone help me to develop this?
please reply if you can

firefox and safari can't connect

i used wsocket in a middleware use and it works good on chrome but on firefox and IOS not.
have you some tips to give me ?
client side:
Firefox non può stabilire una connessione con il server ws://192.168.1.3:55226/socket

server side:
on connection <wsocket.WebSocket object at 0x7f94f5bb9e80> and after
<wsocket.WebSocket object at 0x7f94f5bb9e80> : Connection is already closed

thanks

Gunicorn

i am using Wsocket with a wsgi compatible app based on werkzeug (middleware) . it works but when i try to run the app with gunicorn socket stops to work ( others tradizional routes still works )

gunicorn -w 2 -b 0.0.0.0:55226 zero:app

this is the simple string i use
someone is using in conjunction with uwsgi or gunicorn ?
thanks

the demo "on_close" is not valid

the demo "on_close" is not valid

hello, I used the code and add print message on_close.

=====================================================

from wsocket import WSocketApp, WebSocketError, logger, run
from time import sleep

logger.setLevel(10)  # for debugging

def on_close(self, message, client):
    print("come to the on_close_____________")
    print(repr(client) + " : " + message)

def on_connect(client):
    print(repr(client) + " connected")

def on_message(message, client):
    print(repr(clent) + " : " + repr(message))
    try:
        client.send("you said: " + message)
        sleep(2)
        client.send("you said: " + message)

    except WebSocketError:
        pass

app = WSocketApp()
app.onconnect += on_connect
app.onmessage += on_message
app.onclose += on_close

run(app)

===================================================
$ python3 hello_world.py

Server started at http://127.0.0.1:8080.
DEBUG:wsocket:Protocols allowed:
DEBUG:wsocket:WebSocket request accepted, switching protocols
<wsocket.WebSocket object at 0x7fc744c01100> connected
opcode close
close called
DEBUG:wsocket:Closed WebSocket
receive closed
Connection is already closed
127.0.0.1 - - [19/Mar/2022 00:05:22] "GET / HTTP/1.1" 101 4
close called
receive closed
Connection is already closed
receive closed
Connection is already closed
DEBUG:wsocket:Failed to write closing frame -> closing socket
DEBUG:wsocket:Closed WebSocket

the message above is I run the hello_world.py.
when I closed the websocket connect by the client. It did not go the the " on_close(self, message, client):" ,and not print the message :"come to the on_close_____________"
Some one can try to check the code and tell me why not message is printed on_close?
Thank you!

Exception disappear

there is a small bug in the code in the file wsocket.py at line 409

 def process_response(self,allow_write=True):
  try:
   results=self.app(self.environ,self.start_response)
  except Exception as e:
   self.start_response(500)
   log=log_traceback(e)
   err="<h1>Internal Server Error(500)</h1><p><b>%s :%s</b></p><p><samp><pre>%s</pre></samp></p><a href=\"https://github.com/Ksengine/wsocket/issues/new?%s\" target=\"blank\"><button><h3>report</h3></button></a>"%(type(e).__name__,str(e),log,urlencode({'title':type(e).__name__,'body':issue.format('```python\n'+log+'\n```')}))
   return[err.encode("utf-8")]
   logger.debug(log)

the logger.debug(log) is after the return so when there is an error in a controller of the wsgi app no error is showed

inverting the two rows fixes
thanks for your work

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.