Sockets in Brython not properly implemented?

175 views
Skip to first unread message

Luke Hackworth

unread,
May 22, 2018, 3:00:07 AM5/22/18
to brython
Hi everyone

I've just started off using Brython for a project that needs a browser side Python IDE. I've gotten the basics working but am running into an issue with sockets. Using this simple test example:

#Socket test program
import socket

HOST = '127.0.0.1'    # The remote host
PORT = 5000              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
s.close()
print ('Received', repr(data))

I get the error:
Traceback (most recent call last):
  module <module> line 7
    s.connect((HOST, PORT))
AttributeError: 'socket' object has no attribute 'connect'


I get similar error for methods such as 'accept':
AttributeError: 'socket' object has no attribute '_accept'

Has anyone had any experience with this issue or could provide me with a hint as to what's going on.

Many thanks, Luke

Francisco Javier Vazquez Umbria

unread,
May 22, 2018, 4:02:03 AM5/22/18
to bry...@googlegroups.com
Natively, Javascript does nos support Sockets, so, Brython is unable to support it. Brython is 'Python Over Javascript', so, if Javascript does not provides Socket Support, Brython can't do anything.

You can use XMLHTTP Request, Fetch, WebSockets AND WebRTC, but not raw sockets, sorry.

If you want to do a 'brython server', see WebRTC. is the only way to make a browser 'serve' content.

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/0dc10f58-14f0-494e-961a-16f70357d69d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luke Hackworth

unread,
May 22, 2018, 8:04:47 AM5/22/18
to brython
Thank you very much Francisco

I've managed to implement a test of what I'm trying to do with websockets. Your help is greatly appreciated :)

Luke
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.

Francisco Javier Vazquez Umbria

unread,
May 23, 2018, 5:47:54 PM5/23/18
to bry...@googlegroups.com
You are welcome. Take in consideration that websockets can be deprecated in the future and succedded by webrtc.

To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages