Error creating server

New releases and general discussions.

Post » Thu Feb 21, 2008 7:14 pm

[color=green:1ayd5i3c]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()[/color:1ayd5i3c]

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

[color=green:1ayd5i3c]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[/color:1ayd5i3c]

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
B
2
S
2
G
5
Posts: 293
Reputation: 2,236

Post » Thu Feb 21, 2008 7:39 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Thu Feb 21, 2008 7:43 pm

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
B
2
S
2
G
5
Posts: 293
Reputation: 2,236

Post » Thu Feb 21, 2008 7:53 pm

i just noticed from typing it in manually, "socket" isn't available in the list on the right hand side of the editor
B
2
S
2
G
5
Posts: 293
Reputation: 2,236

Post » Fri Feb 22, 2008 7:55 pm

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:

[color=green:m7wimmsr]Traceback (most recent call last):
File "<string>", line 5, in <module>
file "<string>", line 1, in bind
socket.error: (10048, 'Address already in use')[/color:m7wimmsr]
B
2
S
2
G
5
Posts: 293
Reputation: 2,236

Post » Sat Feb 23, 2008 12:31 am

Some other process is using that port.
Or you used it earlier and didn't close it. (the game crashed or a script error?)
B
2
S
1
G
5
Posts: 50
Reputation: 1,500

Post » Sat Feb 23, 2008 1:56 pm

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.
B
2
S
2
G
5
Posts: 293
Reputation: 2,236

Post » Sat Feb 23, 2008 2:31 pm

You could try ipconfig /renew from the command line instead. I don't know enough about Python sockets to help you though...
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Sat Feb 23, 2008 4:27 pm

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.
B
3
S
2
G
4
Posts: 130
Reputation: 1,735

Post » Sat Feb 23, 2008 5:00 pm

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!
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 3 guests