CodeOnBy - In Between Bytes
  • Home
  • Programming
    • JavaScript
    • Python
  • System
    • Cross-platform
    • Linux
    • macOS
    • Windows
  • Gear
  • About Me
Home
Programming
    JavaScript
    Python
System
    Cross-platform
    Linux
    macOS
    Windows
Gear
About Me
CodeOnBy - In Between Bytes
  • Home
  • Programming
    • JavaScript
    • Python
  • System
    • Cross-platform
    • Linux
    • macOS
    • Windows
  • Gear
  • About Me
Browsing Tag
thread
Cross-platform Linux macOS Programming Python System Windows

Python Chat Server (4 of 7)

December 14, 2019 No Comments

[ Part 1 (Overview) – Part 2 – Part 3 – Part 4 – Part 5 – Part 6 – Part 7 ]

Welcome to my blog’s first tutorial series!

Check out the video for details on the code!

Ayyyyoooo guys! What’s good?

Continuing from my last post, its time to implement the server thread.

A lot of pieces are already in place to handle the server threads, so we should be able to get it done without too much hassle.

There are some minor code changes in the server script which I will only be covering in the video above, so if you’re only following the blog make sure to download the code at the end of the post and compare the changes.

Let’s write some codes!

Server Handler Code

# Server handler
# --------------------------------------------
# This function will listen for connections as daemons
# and keep connected in background.
def ServerHandler(serverIP, serverPort, clientIP):
	sh = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	sh.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
	sh.bind((serverIP, serverPort))
	sh.listen(1)	# Listen for 1 client, each server = 1 client
	
z,b = sh.accept()
	if (z):
		print "\n[" + GetTime() + "] Connection from " + str(b)
		while True:
			msg = Receive(z)
			if len(str(msg)): print "\n[" + GetTime() + "] " + msg

There isn’t much to the server handler. Basically we fire up a socket using the supplied arguments serverIP and serverPort – this port is the one supplied by the AllocAddress() function we created in the previous part (will basically add +1 to the same port of the main server).

Continue reading
Reading time: 3 min
Share:
Written by: codeboss
Cross-platform Linux macOS Programming Python System Windows

Python Chat Server (3 of 7)

December 13, 2019 No Comments

[ Part 1 (Overview) – Part 2 – Part 3 – Part 4 – Part 5 – Part 6 – Part 7 ]

Welcome to my blog’s first tutorial series!

Check out the video for details on the code!

What’s going on guys? Are ready to keep on coding?

In this part we won’t write too much code, mostly we’re going to focus on the building blocks to setup our server thread in the future.

This includes setting up a few variables, some new functions and some overall analysis into how the server thread is going to work.

I already explained in the overview how the program is going to operate in regards to handling clients but now we’re actually going under the hood.

Without further ado, let’s code!

Dive Into The Code

On the server script, we’re going to add two new functions:

  • CheckAddr(port, verbose)
  • AllocAddress()

The purpose of these functions will become clear later on, but for the time being we are going to use them to check if the IP address we chose as a host is available; while the second function will work to find an available port for the client to connect back to us (in the client thread, which will be developed later on).

Continue reading
Reading time: 4 min
Share:
Written by: codeboss

Recent Posts

  • Python for Data Recovery
  • Data Recovery using Hex Editor
  • File Transfer in Python 3
  • Intro to SQL Injection (Lab #1)
  • Apache, MySQL & PHP Setup (Win/Linux) for SQL Injection Labs

Recent Comments

  • Brian on Brute-Force VeraCrypt Encryption
  • zhiftyDK on ARP Spoofing with Scapy
  • Alex on Python for Data Recovery
  • john on Data Recovery using Hex Editor
  • Someone1611 on Bind Shell in Python 3

About me

My name is Felipe! I’m a programmer from NY.

Blogs about coding, operating systems, network and security.

Hosting

© 2020 Copyright CodeOnBy // All rights reserved
In Between Bytes