2

I'm currently coding a socket server in Python (VS2012 addon) But I'm stuck and can't get a new socket from an accepted connection.

while (True):
    new = sock.accept()

    acc_addr = new[1]
    ip = acc_addr[0]
    connid = acc_addr[1]

    print 'Received connection from ' + ip + ':' + connid.__str__()

This is what I use, but now I want a new socket() instance for the connected user for my other class (for receiving, sending etc), but how would I get the new socket() instance?

1
  • I do it on VS2012 but I didn't notice it wouldn't be indented at the code. Commented Apr 29, 2013 at 16:01

1 Answer 1

2

Your new tuple returned by accept() has 2 elements: at [1], there is the address tuple, consisting of the ip and the port (named connid by you) - and at 0 there is a socket object which can be used for communicating with the client.

So just do clsock = new[0] and you have your socket() instance.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.