Simple python sockets.

antidrag

New Member
Messages
2
Reaction score
0
Points
0
After a few days of struggling, I got a python codes to work with my hosting account. I am having a bit of trouble running a specific code though (Also I read the TOS and didn't see anything against running a socket server.)
Code:
#!/usr/bin/env python
print("Content-type: text/html\n")

# TCP server example
import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("", 8000))
server_socket.listen(5)

print "TCPServer Waiting for client on port 8000"

while 1:
    client_socket, address = server_socket.accept()
    print "I got a connection from ", address
    while 1:
        data = raw_input ( "SEND( TYPE q or Q to Quit):" )
         if (data == 'Q' or data == 'q'):
            client_socket.send (data)
            client_socket.close()
            break;
        else:
            client_socket.send(data)
 
                data = client_socket.recv(512)
                if ( data == 'q' or data == 'Q'):
            client_socket.close()
            break;
        else:
            print "RECIEVED:" , data
After playing around with the code, I noticed that the print function wasn't working after the line:
Code:
server_socket.bind(("", 8000))
I'm obviously a newbie to python, but does this mean I can't bind a port to an ip with this host? Can functions even be disabled in python like php?

I appreciate any help.
 
Last edited:

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
Script Hosting: Space provided by x10Hosting is to be used to create a functional website, we do not allow bots, content scrapers, or any other script that runs continuously on your account. Any scripts that are executed via cron or manually must be directly related to your website.

^ There's the part of the TOS that wouldn't work, besides the fact that it is more than likely possible to block functions in python the same as you do in php. In any case, what reason would you have to bind a socket on x10hosting anyways?
 

antidrag

New Member
Messages
2
Reaction score
0
Points
0
Why I need a socket server.

I'm not trying to build anything lowbrow, I'm just trying to make a socket server that can support flash games. I'm developing a multiplayer flash game which needs a socket server for players to connect to each other. There were two other methods I considered:

#1 Use http polling with a php file
While this method would work on almost any server. It eats up bandwith and it can only update every 3-5 seconds. Too slow for a live action multiplayer game.
#2 Use flash's media server
This method would be best suited for someone who has a lot more money than I do. It costs hundred for anything for anything more than 5 connections at a time. Seems like a nice alternative, but I definitely don't have the money.

So this would be relevant to the content of the website, since the entire site would be built for this game. Hope this helps clarify what I'm trying to do.
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
It does indeed clarify it, but it also puts it firmly in the realm of "Not on x10hosting" - you need a vps or an actual server for what you're doing, not a website host. X10's part of the TOS where it says this:

Script Hosting: Space provided by x10Hosting is to be used to create a functional website, we do not allow bots, content scrapers, or any other script that runs continuously on your account. Any scripts that are executed via cron or manually must be directly related to your website.

Stops yours from working. Your server would have to be continuously running to maintain the bound socket anyways, which is banned explicitly. X10hosting's webservers can't be used for hosting a game server.



Edit: Quick update too, won't work on paid for a similar reason. The only x10 service it would work on is a VPS, but that does costs $ monthly. It's better than a few hundred, but it's also completely up to you to set it up and admin it; vps's are unmanaged and can be a pain to put it lightly :)
 
Last edited:
Top