How to Host a Python Socket Server Online (For Free)
Key Takeaways
This video tutorial demonstrates how to host a Python socket server online for free using a cloud provider, with steps including setting up a headless Linux server, transferring server-side code, and connecting clients. Tools used include Putty, WinSCP, Node, Linux, and Ubuntu.
Full Transcript
hey guys and welcome back so in this video what I'm gonna be doing is showing you how to deploy a Python server client system to the Internet so you can play from anywhere now what I mean by this is essentially any program you've created using sockets and maybe you're running it through your local network now you actually want to deploy it to the internet so that anyone can play from any computer around the world well how do you go about doing that now the first thing is you actually can do this on your host computer so whatever computer you're working on your main one you can set it up so that that you know deploys the game and you can play from anywhere that's usually not a good idea because that means you're kind of leaking your IP address and allowing people to connect to your machine and your home network which is usually just not the best practice and safest idea so what we're gonna be doing in this video is showing you how to set up a very basic headless server which is just gonna be used by like a cloud provider in this case we're gonna use Leno Dan I actually have a free $20 credit to give you guys which will allow you to use this for about 4 months for free so me showing you how we can do this which just means kind of working in Linux and a bun to how we can transfer some files over and how to just get everything set up and running smoothly so with that being said let's go ahead and get started with this video and we need to download a few things before we can really move into anything else so the first thing we're gonna need is putty this is gonna be our SSH client which is going to allow us to connect to our server which you know we obviously don't have right in front of us and do some things with it so log in add the Python script run some stuff see some output all of that so download putty the link is right here and there'll be a link in the description if you want to just click that to get to that the next thing we're going to download is called win SCP this is a very basic File Transfer Protocol or I guess you could call it clients maybe you could use FileZilla any other kind of File Transfer Protocol that you want but I just like using this one because it's really basic really straightforward so go ahead and download this it's not very big as well it's only nine point four gigabytes so once we have those two what we're gonna do is set up a really basic minimal server on the node now again I am partnered with one note I actually don't get paid if you guys sign up for this I don't really care if you use it or not but you can have a twenty dollar credit and you know you can use this for four months for free so if you just want to mess with you might as well you know just take the credit sign up and use it so to do this there's a link in the description but you can just go to low note comm slash tech with Tim or you can use the code twt 19 that'll give you $20 off so I'm gonna click the deploy Milan ode server now for you guys what's gonna happen is probably until you need to create an account so do that and then it should give you $20 credit and if for some reason it doesn't work just type in that code twt 19 now once we're here to set up Allen owed which are just gonna be our server we're gonna click on create and I'm gonna click on the node now for this purpose what we're gonna do is select our OS and in this case I'm gonna choose some version of Ubuntu so I'm just gonna pick the most version most recent version of Ubuntu it doesn't really matter which one you pick so long as you know how to work with it alright for our location I'm closest to Toronto so I'm gonna select that and then for our plans we're actually gonna go to Nano and select this five-dollar plan now you mean like you guys can use the ten dollar plan if you want or the twenty dollar plan but I mean if you want this to last for as long as possible just pick the five dollar plan that's the cheapest one they have now for this label I'm just gonna call this tutorial because I am gonna delete this after and then we need to select a root password which we need to remember because that's what we're gonna use every time we sign in so I'm just gonna make my password one two three four you guys can make it whatever you'd like alright so now that we have that that's pretty much all we need to do and we can just go ahead and click create now I gotta choose a better password okay so let's do another password which I'm not gonna tell you guys what it is okay so there we go create a password I don't need to save that and now it's gonna take a second and set up Arlen ode and once that's done we'll be right back and we can move into the next steps alright so I mean the note is up and running now you can see that by the fact that it says running and I mean if you want to restart it or power it down you can click this now I'd recommend when you guys aren't using this if you want to save your credits just stop this because the five dollars a month assumes that you're running it consistently for 30 days or each month or whatever it is so if you actually stop running it then you only get paid charged by the hour so you get charged like I don't know point seven five cents per hour something really small so I mean you could technically use this for a really long if you only use it for a few hours at a time okay so now that we have that we actually need to go here to the networking tab of our lenôtre look for this IP address here so mine is one 72.1 oh five oh sorry not that one we need to actually look for the ssh IP address which is one 72.1 oh five or ten now this IP address here I'll zoom in a bit so you guys can see it where the ssh access is is what we're actually going to use to access our computer from putty so this again is just like a computer running in the cloud it exists somewhere but we don't have access to it so we need to SSH into it so that we can actually controlled and start doing some things so we're gonna go ahead and open up putty here like this now I'll zoom in on this you guys can see it what we're gonna do is create a new kind of profile I guess and putty and set this up so we can access our server so what I'm gonna do is take that IP address so that 172 that I have and I'll just paste it right in here now where it says save sessions what I'm gonna do is I'm gonna type I guess like tutorial like that and go ahead and hit save now what this is gonna do is actually save this IP address in this port number 22 it's fine to leave it like that into a profile called tutorial so now every time when you load putty rather than having to type this in you can just select tutorial and hit load and it will load that profile now I usually like to just make my text size a bit bigger too so what I do but so to do that we're gonna go to appearance we're gonna go to change and I'm just gonna change that font size to 20 just so I can actually read it because otherwise it's very small so anytime we make a change we need to resave this change so since tutorials right here is save sessions we'll hit save again and now that'll save that in the tutorial profile and we can load it by just you know hitting load again okay so now that we have that all we're gonna do is go ahead and hit open now when we hit open it's going to bring up this warning which you guys can see here security breach just go ahead and hit yes it's not a huge deal at all and what we're gonna do for the login is we're gonna type route now route is your main user and that's the default user that comes with your I guess a bun to server so hit route that's this will be the same for all of you and for your password you're gonna type in that password you created when we created the lenôtre so I'll type in my password it's not gonna show up on the screen you just have to type it and hit enter okay so now we have this server you can see kind of some information here so it says like the memory usage all of that I'll show you a really cool trick if you want to see kind of all the things that are running on your server and you just want to look cool go ahead and type each top and that's actually brings up kind of like the task manager for your server so say you're not sure you know how much memory you put in or how many CPUs you have well you can just look here and it'll tell you kind of what's being used and you can go through all of this stuff here and look at all the processes that are running on the right side of the screen that's useful because sometimes you need to kill processes and I'll show you how to kill one without actually killing it so for example each top is a process that's running you can see the command so if I hit f9 that stands for kill and then I hit enter it will actually kill each top and stop running that process okay so now that I've showed some basic stuff here let's just show kind of how to navigate through this server from the command line and then we'll actually transfer some Python files over and show how we can actually get all this running so what I'm gonna do is show you a basic command which is C D now C D stands for change directory so to change directory what you do is you type C D and then you type the name of the directory you want to change into now sometimes you don't know what directories are available to move into so to see this we're gonna type is LS now actually don't know what that stands for but I think it's like a list something but anyways that'll actually show you all the directories that are in this directory now you can see here there's actually none because nothing popped up so if this is the case there's nothing that we can move into now what we can actually do is type something called CD dot dot now what this does is actually move us back a directory level so say we have two folders we have a folder called main and we have a folder called sub and the folder sub is inside main say we're currently you know in that folder sub we type CD dot dot it'll bring us into that main folder and then we can reenact it in two other points or just moves you back a directory level so if I hit that you can see that now we change from this little squiggly line here which i think is called like the tilde and now we have a slash so now if i type LS you can see that it brings up all these different folders that are nice and color-coded for us that tell us you know where specific things are now what we typically do actually I don't know if what's what we typically do but what I usually do and I'm doing this is I just CD into my root directory which is one you default like it default puts you in so you go CD root and I create a new folder so to create a new folder you're actually gonna type mkd which stands for make directory and you're gonna type the name of the folder you want to create so in this case I'm gonna say Python - server like that so I'm caterer - server and now if i type LS to list the directory you can see that we have this Python server so what I'm gonna do is actually change directories into this Python server by doing CD python - server now show you guys a quick trick here what you can actually do is if you have this CD and you know kind of the beginning of the name of the folder you don't want to type the whole thing just start typing a few letters so let maybe just pipe and then hit tab it will actually autocomplete the rest of that folder for you assuming it knows which one you're talking about so we can hit enter there and now you can see we have root which is this tilde slash Python server and that's what we currently are alright so now that we're here fortunately for us python is actually installed on this lenôtre already so python 3 if you type that actually pops up we already have the most recent version of python but you may need to install python by doing like sudo apt - get and then python 3 or whatever it is that you want but most of these servers come with Python by default so we don't actually need to do that alright guys I'm back now I just realize I had the wrong code up on my left side of my screen here so had to change that before we continued and he was what I'm gonna show you now is how we can actually modify the code that we've written so that it works on our new server online this is really basic to do but I'm just gonna say quickly if you just don't have this code this is just a really like basic script that essentially allows you to move to little rectangles around to different screens from any computer if you don't have this and you want to mess with it I'll leave a zip file down below so you can download this code this will work with any kind of socket program you've written so any if you fold any of my other tutorials with online games this should work for you ok so what we're gonna do to start is gonna go into our server script here which I have right here and we're just gonna make sure that whatever Aiki address we're binding to the socket is blank so what I mean by that is right now you can see I have like server equals 192.168.1.1 I'm just gonna delete that and leave this as a blank string so now when I bind to the server it binds to a blank string and what that means is just bind to any available IP address which will end up binding to the actual server itself and that will be like a better way of doing this so anyways now that we have that what we need to do is go into our other file where we're actually connect to the socket which I believe is network at least for me it is and we need to change the host or whatever we're going to be connecting to to actually be the IP address of this server so in this case the IP address is 1 72.1 o 5.4 10 so I'm going to change this host attribute here to beat that make sure this is formatted correctly and that's all we need to do is just change those IP addresses around and we should actually be good and ready to go now some people say oh you do port forwarding you gotta do this you don't necessarily need to do that it kind of depends on what program you're running I in our case we don't need to do any port forwarding and that's a more advanced thing that I'm not gonna talk about here ok so now that we've done all that what we need to do now and this is kind of the only thing is take this server file transfer it to our server and then run the file and then we can run clients from wherever we want and connect to them so how do we do that well what we're gonna do is open up win SCP which is gonna be our file transfer client I guess and we're gonna create a new site by hovering over a new site here and we're gonna go ahead and type in a host name of in this case whatever the IP address of our server is so one seven two one oh five or 10 we're gonna type in the username as root because that's the username we're gonna login with and the password as whatever that root password is and we're gonna go ahead and hit save here and save this as whatever you want you can leave that IP address I'm just gonna save this as tutorial server like that go ahead and hit OK and then you might pop up this thing saying like oh there's the security issue just hit yes it's fine it doesn't really and then we can go ahead hover over this and click login now it's gonna ask you for the password again so just type it in and hit enter or hit OK alright so now that we're there we can actually see it brings up our Python server here and we can actually navigate into there I have this PI cache file and delete that you guys won't have that file just because I was messing with something but anyways that's how we kind of navigate through our actual server is on here so if I go back a root directory you can see now we're outside of that root directory and if I want to go back I can select root and then Python server it's just like navigating through any kind of Windows file system except now you have a nice little client to do it for so the way this works is kind of your computer's on the left side the servers on the right side and to transfer stuff over you can just drag and drop but you can also just drag and drop from like a Windows Explorer like this you can just drag it right in which is exactly what we're gonna do so what I'm going to look for now actually is my code here so I'm gonna find the directory that's in and I'm just gonna drag whatever server files I need onto the server now I'm not gonna put any of the client files because I don't need those on there I'm just gonna put the server ones so to do this I'm gonna find that which is gonna be challenging but I think I know where it is but all right so I found the files now so what I'm gonna do is just drag the server file here as well as the game file which is another one that I need and now that I have these on here all I actually need to do to run this is go on the server and run my server dog Pi script and then connect to it from my client now I did this earlier and I got some air anyways because I was trying to test this before I actually went in that's because I was using like the wrong server script but anyways ignore that I just figured I'd mentioned on in case any of you guys were like confused what was going on on the left side of my screen ok so what I'm gonna do now is actually close win SCP because we don't need that anymore I'm gonna open up putty which I have here you can see I deleted the old files that weren't working so let me just clear this and what I'm gonna do now is do LS and you can see that we actually have these two files so gamed up high and server top pie just in case anyone's confused just like if you saw me having all these weird things going on just ignore that because I made a quick mistake so I had to fix something in this video but anyways what we're gonna do now is simply run this server script so once we've transferred those files over we've transferred game we've transferred server whatever files is we need we're gonna run Python 3 server dot PI now make sure you do Python 3 because if you do Python that's gonna run Python 2 and you're probably gonna run into some errors so let's go ahead and hit enter and you can see now it says waiting for a connection so now that it says that's what I'm gonna do is go to my actual game here on my computer and remember this is a different computer this is the actual server and I'm going to go ahead and run my script that should connect to this so I'm gonna hit control B and you can see that now we get connected to and we have this window popping up and all these sending and receiving are happening now look I can actually move this dot around and notice that on my server it's showing all of these things and there's actually very little latency between the server and this client script here now it's hard for me to illustrate this works on a bunch of different computers but I'm just gonna run another client on this specific computer and show you guys how this works give me a second to actually or actually already have this open so I can just go CMD and then Python run PI and now there's another one that pops up here and you can see we have two clients and if I move one here it will move on the other client with a little bit of latency but nothing that's too bad so I mean that is kind of how you run this you get the server script running on the server and you get the client scripts running on your clients now I will tell you these things are pretty finicky and it takes kind of an expert in this field to figure out the best way to code a server and the best way to code a client so you don't get a ton of latency and lag like the way that I'm doing this is probably not the most efficient this is just a really basic game that I wanted to show you and you know test some things out so anyways this is kind of how that works this is the server but I'm just going to show you one last thing so I'm gonna exit this by just hitting ctrl C now the only issue that's gonna occur right now is that if I actually closed this putty window my server is gonna close as well so like these here so they're frozen anyways because I closed this but those will eggs it as well and they'll be an error and that's because this when I run Python 3 it runs kind of like through my display which means if I close this it closes this kind of terminal session and stops running that so what we need to do to fix this is we need to actually use something called screen now what screen does is it detaches the process which is that Python 3 server at PI that's the process from our computer and it just puts it and runs it directly on the server it's kind of hard to explain like exactly how this works but essentially when you just run this without screen it's attached to your kind of display which means when you close this it stops running on the server but if you put screen before whatever command you run then that means that you can essentially you know have that running 24/7 it doesn't matter whether or not you have this open or not okay so what I'm gonna do is gonna type screen and let's just see if this works oh screen does work but for some of you guys let me actually get out of this for some of you guys you might not have screen on your I guess server so what you need to do is type sudo apt - get I think it's - get install screen let's see if that works yeah so that does actually work screen is already installed on my computer but this will actually install screen for you so that you can use it okay so now that we have screen we're gonna use screen and then we're gonna types on my same server Python 3 server pot now if you spell python correctly which i did not there and you run this then you will see that it actually runs this and it looks like a little bit different the way that it runs it but this now means that this is detached from our display and this will work no matter what so we can go ahead and connect to this again so control B and you can see that we're still connected and if I actually go ahead and close this window here so let's close the session and ice to try to move around this still actually works now if I run another one here I think yeah I can just do it like that so let's get these two PI game windows open and I start moving around you can see that everything is still working fine and doing that screen has actually fixed that for us and everything is working now the last thing I'll show you is that you know like when you run it with screen well how do you quit it afterwards well to do that we need to go back into putty we need to load up our tutorial again and then what we need to do is login like we did before need to type each top we need to find this process on the side if we want to quit this server process and need to actually just quit it so we're gonna find the command that we type so here it says Python 3 user unattended so we're gonna do is or sorry that's not the one it's here python 3 server top pipe we're gonna hit f9 for kill and then we're gonna hit enter and then that will actually kill the server for us so now that is not is no longer running on our machine now to wrap up this video I do need to say I do have an affiliation with lenôtre and that's the reason they provide you guys with a free $20.00 credit that can last you for months to kind of test out and play with the basic level plan for a server now the note has an awesome support team so because you do need help and for some reason I can't or my discord server it can't help you can always reach out to them and they'll be more than happy to do that it's available 24/7 365 days a year that's by online or by phone this is kind of random but if any of you guys live in Australia you might be excited by this because they're actually opening a new data center in Sydney at the end of 2019 which is kind of nice because usually if you live in Australia I know that like Server companies and internet providers don't really mess with it just because of its the location in the world but that's nice and that's gonna be I think their 11th data center that they have so anyways if you guys enjoyed this video please make sure you leave a like and subscribe definitely sign up and take advantage of this free credit there's no obligation you have to pay for anything and I mean just go ahead take it and use it
Original Description
This tutorial will walk you through hosting a python socket server online where it can be accessed and connected to from anywhere. We will setup a headless linux server and transfer our server side code there. After running the code from our server we will connect our clients.
Get a free $20 credit on Linode using the code TWT19: https://www.linode.com/techwithtim/
DOWNLOADS:
puTTY: https://www.putty.org/
winSCP: https://winscp.net/eng/index.php
MY CODE:
https://dev-cms.us-east-1.linodeobjects.com/Network_Game_Tutorial_2ea81337f6.zip
◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python
https://tech-with-tim.teachable.com/p...
📸 Instagram: https://www.instagram.com/tech_with_tim
🌎 Website https://techwithtim.net
📱 Twitter: https://twitter.com/TechWithTimm
⭐ Discord: https://discord.gg/pr2k55t
📝 LinkedIn: https://www.linkedin.com/in/tim-rusci...
📂 GitHub: https://github.com/techwithtim
🔊 Podcast: https://anchor.fm/tech-with-tim
💵 One-Time Donations: https://www.paypal.com/donate/?token=...
💰 Patreon: https://www.patreon.com/techwithtim
◾◾◾◾◾◾
⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
Tags:
- Tech With Tim
- Python Tutorials
- Python Socket Server
- Host Python Sever Online
- How to Host Python Socket Server
- Python Server
- Free Python Server
#python #sockets #networking
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Let Me Show You Which AI Model Actually Writes the Best Code
Dev.to · gentlenode
What Actually Happens When You Press Enter in ChatGPT?
Medium · AI
What Actually Happens When You Press Enter in ChatGPT?
Medium · Machine Learning
I Built an AI-Powered LeetCode Auto Solver Chrome Extension (Using JavaScript + LLM APIs)
Medium · LLM
🎓
Tutor Explanation
DeepCamp AI