When I have successfully connected to a socket like this:
import socket
network = socket.socket()
network.connect_ex(("my ip", 61111))I am trying to send something to the port like this:
network.send("Hi")But I get an error!
Python Shell wrote:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
network.send("hi")
error: [Errno 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
HELP!
Offline
ohaiderstudios wrote:
When I have successfully connected to a socket like this:
Code:
import socket network = socket.socket() network.connect_ex(("my ip", 61111))I am trying to send something to the port like this:
Code:
network.send("Hi")But I get an error!
Python Shell wrote:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
network.send("hi")
error: [Errno 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was suppliedHELP!
![]()
Out of curiosity, what is connect_ex()?
Offline
Magnie wrote:
ohaiderstudios wrote:
When I have successfully connected to a socket like this:
Code:
import socket network = socket.socket() network.connect_ex(("my ip", 61111))I am trying to send something to the port like this:
Code:
network.send("Hi")But I get an error!
Python Shell wrote:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
network.send("hi")
error: [Errno 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was suppliedHELP!
![]()
Out of curiosity, what is connect_ex()?
It's like connect, but returns a warning code instead of an exception when it fails!
Last edited by ohaiderstudios (2011-12-22 17:52:40)
Offline
Hang on, I think I may know the problem now...
This ruins everything!
Last edited by ohaiderstudios (2011-12-22 17:52:14)
Offline
Okay, now I replaced "connect_ex" with "bind", and I connect fine, but when I try to send, I get the same error?
Does 'bind()' not keep the connection going or something?
Last edited by ohaiderstudios (2011-12-22 18:16:43)
Offline
ohaiderstudios wrote:
Okay, now I replaced "connect_ex" with "bind", and I connect fine, but when I try to send, I get the same error?
Does 'bind()' not keep the connection going or something?
Do you have a server running? Bind is for servers.
Offline
Magnie wrote:
ohaiderstudios wrote:
Okay, now I replaced "connect_ex" with "bind", and I connect fine, but when I try to send, I get the same error?
Does 'bind()' not keep the connection going or something?Do you have a server running? Bind is for servers.
Now I'm seriously confused...
Okay, let me try to understand:
The server binds to a port so that the client can connect to the server?
Offline
Offline
Magnie wrote:
I DON'T NEED THAT!!!!
I FIGURED IT OUT!!!!
IT WORKS!!!!!!
YAAAAAAAAAAAAAAAAAAAAAAAAAY!!!!!!!!!!!!!!!!!!!!!!!!!!!
I think...
Offline
ohaiderstudios wrote:
Magnie wrote:
I DON'T NEED THAT!!!!
![]()
![]()
![]()
![]()
I FIGURED IT OUT!!!!![]()
![]()
![]()
![]()
IT WORKS!!!!!!![]()
![]()
![]()
![]()
YAAAAAAAAAAAAAAAAAAAAAAAAAY!!!!!!!!!!!!!!!!!!!!!!!!!!!
![]()
I think...
How? Please post so other people can see how you did it for future reference.
Offline
midnightleopard wrote:
ohaiderstudios wrote:
Magnie wrote:
I DON'T NEED THAT!!!!
![]()
![]()
![]()
![]()
I FIGURED IT OUT!!!!![]()
![]()
![]()
![]()
IT WORKS!!!!!!![]()
![]()
![]()
![]()
YAAAAAAAAAAAAAAAAAAAAAAAAAY!!!!!!!!!!!!!!!!!!!!!!!!!!!
![]()
I think...How? Please post so other people can see how you did it for future reference.
Basically, in order to open a port for clients to connect to, you need to use
network = socket.socket() network.bind((ip, port)) network.listen(backlog)
As Magnie pointed out, "bind()" is only used for the server side, so the client uses
sock = socket.socket() sock.connect((ip, port))
It was just a little bit of confusion on my part. Magnie could probably explain it better.
Offline