Overclock.net - An Overclocking Community

Overclock.net - An Overclocking Community (https://www.overclock.net/forum/)
-   Coding and Programming (https://www.overclock.net/forum/142-coding-programming/)
-   -   Does python have networking? (https://www.overclock.net/forum/142-coding-programming/1572627-does-python-have-networking.html)

Higgins909 09-05-2015 08:54 PM

I'm trying to learn python from learnpythonthehardway.org and I'm about half way through.
I've looked at the index or whatever its called (don't know book terms) and it never mentions anything about networking. Only at the end does it say something like move onto ruby..

Does python have networking... Like I could make a game and have people connect over lan/wan?
Does ruby?

Thanks,
Higgins909

DuckieHo 09-05-2015 09:04 PM

Sure... python has network libraries/modules natively....

http://www.tutorialspoint.com/python/python_networking.htm


Just learning to networked gaming is quite a big jump....

Higgins909 09-10-2015 06:32 PM

... rather confused with the word native attached to libraries. Does that mean I've got to learn another language? as that answer mentions c/c++ and normal dll and libs.
This is a example I was able to find that at least made some sense, but confused me on other parts.

This was in a java area.
"Native Library" generally means a non-Java library that's used by the system (so C/C++, etc). Think normal DLLs or libs.

What about graphics? Would it be called a gui in this case? I know linux has cli and gui versions... in a game is it called a gui still?

aldfig0 09-10-2015 06:58 PM

It means that by virtue of installing Python you've already got the standard library included. All you have to do is type "import socket" in your .py file and you can use everything in the socket module by typing socket. and the function name and arguments after the dot.

If you're clicking at things in your game instead of just typing in commands then your game uses a graphical user interface. If you want to do this note that Python has Tkinter built in its standard library which will easily allow you do create a GUI. You can also use third-party ones like PyQt, wxPython, or PyGame (which should have game-specific features but I've never used it so I can't be too sure).

Mrzev 09-15-2015 11:26 AM

Whenever i need to listen to a port for data and do something with it, I tend to go with python because it's pretty quick and easy. This script listens to port 5555 and writes the data into an SQL db.

Code:
#!/usr/bin/python
import socket
import sys
import json
import mysql.connector
from datetime import datetime

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to the port
server_address = ('', 5555)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)

print >>sys.stderr, 'Started - Listening'
while True:
        # Wait for a connection
        
        message = ""
        connection, client_address = sock.accept()
        try:
                print >>sys.stderr, 'connection from', client_address
                while True:
                        #Loops trough 1KB at a time until it received all the data.
                        data = connection.recv(1024)
                        message += data
                        if not data:                            
                                print message
                                print " "
                                jdata = json.loads(message)
                                
                                cnx = mysql.connector.connect(user='', password='',
                                                                  host='127.0.0.1',
                                                                  database='test')
                                cursor = cnx.cursor()
                                type= jdata["MovementForward"][0]["Device"]["type"]
                                name = jdata["MovementForward"][0]["Device"]["name"]
                                x= jdata["MovementForward"][0]["Device"]["movements"][0]["Movement"]["points"][3]["PointLoc"]["x"]
                                y= jdata["MovementForward"][0]["Device"]["movements"][0]["Movement"]["points"][3]["PointLoc"]["y"]
                                date_object = datetime.strptime(jdata["MovementForward"][0]["Device"]["movements"][0]["Movement"]["date"], '%Y-%m-%dT%H:%M:%S+0000')

                                cursor.execute("INSERT INTO locations (type,name,x,y,dateReceived) VALUES (%s, %s, %s, %s, %s)",(type, name,x,y,date_object))
                                cnx.close()
                                
                                break
        finally:
                connection.close()


markgeven 12-09-2018 11:03 PM

Python Networking
 
Python Networking Programs..

http://net-informations.com/python/iq/default.htm

PhotonFanatic 12-11-2018 01:47 PM

A bit off topic, but it looks like learnpythonthehardway.org is just a site that sells a book. Am I missing anything here?

Cloudforever 08-17-2019 01:30 PM

you guys rock. Those links you've provided greatly helps.

Thanks!!


All times are GMT -7. The time now is 02:43 PM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
vBulletin Security provided by vBSecurity (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.

vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.