Posts Tagged ‘chat’

PostHeaderIcon P2P Drawing and Chat Program in Python

Network Programming in Python and Graphics

In this Tutorial I will try and explain simple Networking concepts in Python. Some things you will learn here are GUI programming, Networking, threading and hopefully enough understanding to be able to send binary data over the network.

from Tkinter import *
import socket
from threading import *
import cPickle

Our import statements you will notice we import our GUI modules, our socket modules, threading for keeping the GUI from freezing during connections. Finally cPickle his allows to send binary data over the network

CMD_MSG, CMD_LINE = range(2)

create some global variables

first we define our server function assign a port to listen to and bind it to our IP address


def server():
port = 9000
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((socket.gethostbyname(socket.gethostname()), int(port))) # bind to ip

next we create our loop
Read the rest of this entry »

Search
Awesome Links
Subscribe
Vote for Flyninja
Random Reading