Error creating server

This forum is currently in read-only mode.
  • import socket

    mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )

    mySocket.bind ( ( '', 2727 ) )

    mySocket.listen ( 1 )

    while True:

    | channel, details = mySocket.accept()

    | print 'We have opened a connection with', details

    | print channel.recv ( 100 )

    | channel.send ( 'Green-eyed monster.' )

    | channel.close()

    i tried copying and pasting this code from a tutorial into construct but i got this error:

    Traceback (most recent call last):

    File "<string>", line 1, in module>

    File "C:\Python25\lib\socket.py, line 45, in <module>

    importError: No module named _socket

    my guess is that the socket library isn't available but then again, i don't know very much about the python language so please help! i wanna get construct up and running online YESTERDAY! =P

  • Seems to import OK here - are you sure there's not a typo or something? What you pasted imports 'socket', but the error message said it was looking for '_socket' with an underscore.

  • everything i copy and pasted is from this page

    http://www.devshed.com/c/a/Python/Sockets-in-Python/1/

    word for word, case for case

  • i just noticed from typing it in manually, "socket" isn't available in the list on the right hand side of the editor

  • so i tried installing python just to see what would happen and now it doesn't give me any message about a missing module but now i get this message:

    Traceback (most recent call last):

    File "<string>", line 5, in <module>

    file "<string>", line 1, in bind

    socket.error: (10048, 'Address already in use')

  • Some other process is using that port.

    Or you used it earlier and didn't close it. (the game crashed or a script error?)

  • ah yes, that's the message i get every time i try to play test after running the above python code with python installed. rebooting is the only way to get around it, apparently.

  • You could try ipconfig /renew from the command line instead. I don't know enough about Python sockets to help you though...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think if you somehow tested to see if the socket is open on startup before opening it, that problem could be worked around.

    Basically if it's not open it opens it, if it's open it does nothing.

    I'm not sure about doing this in Python but there should be some way to ping a port on your local machine via localhost, and then just a simple if/then/else operation could solve that.

    Also, I'm not sure about the Python library that Construct 0.91 ships with, but I think it may lack the sockets library. So that would have to be included with the game (I think) for sockets to work. Not 100% sure on this, and the fact that I just spent five hours working on a native 1280x800 monitor, in 640x480 safe mode, really hasn't helped my mental condition.

  • Construct supplies all the Python libraries and attaches them to any exported EXEs - including socket and StringIO - and it must be finding StringIO, because it is required for Python to work at all with Construct... hmm, I'll think about it!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)