Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate error "Protocol wrong type for socket". #49

Open
johnnykv opened this issue Jul 28, 2017 · 1 comment
Open

Investigate error "Protocol wrong type for socket". #49

johnnykv opened this issue Jul 28, 2017 · 1 comment
Labels

Comments

@johnnykv
Copy link
Owner

Using this code

import socket
HOST = 'localhost'    # The remote host
PORT = 25              # The same port as used by the server

i = 0
while i < 100:
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.connect((HOST, PORT))
        s.close()
        i = i + 1

the exception below was generated on OS X, this needs to be investigated.

2017-07-28 17:57:34,011 (asyncio) Fatal write error on socket transport
protocol: <asyncio.streams.StreamReaderProtocol object at 0x10e047ef0>
transport: <_SelectorSocketTransport fd=35 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/selector_events.py", line 702, in write
    n = self._sock.send(data)
OSError: [Errno 41] Protocol wrong type for socket
2017-07-28 17:57:34,056 (asyncio) Fatal write error on socket transport
protocol: <asyncio.streams.StreamReaderProtocol object at 0x10e44f9e8>
transport: <_SelectorSocketTransport fd=31 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/selector_events.py", line 702, in write
    n = self._sock.send(data)
OSError: [Errno 41] Protocol wrong type for socket
@johnnykv johnnykv added the bug label Mar 17, 2019
@viditgarg1999
Copy link

Maybe it’s showing error because there is a mismatch in the protocols, like the code is written in
UDP protocol but in the selectors_event.py file (line no. 702)
n = self._sock.send(data)

we have used .send which is used in TCP protocol, instead of writing it as .send try changing it to .sendto (used in UDP protocol)

Hence the command become,
If the file is client file and the data is in encrypted form then command will become,
n = self._sock.sendto(data,((HOST,PORT)))

and if data is not in Encrypted form,
n = self._sock.sendto(data.encode(),(HOST,PORT))

Now if the file is a server file and data is in encrypted form then the command will become,
n = self._sock.sendto(data,addr) here addr is the address of the clinet
and if the data is not in Encrypted form,
n = self._sock.sendto(data.encode(),addr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants