Python

Python Documents

ภาษาโปรแกรมมิ่งไพธอน
wxPython Tutorial
http://zetcode.com/wxpython/
Matplot Examples

Python Downloads

1) python-2.7.3.msi
2) wxPython2.8-win32-unicode-2.8.12.1-py27.exe
3) wxPython2.8-win32-docs-demos-2.8.12.1.exe
4) SPE-0.8.3.c-wx2.6.1.0-py24.exe (Run as administrator)

How to Add Python to Windows Path

  1. Open System Properties (type it in the start menu, or use the keyboard shortcut Win+Pause)
  2. Click Advanced system settings and switch to the Advanced tab
  3. Click Environment Variables...
  4. Select PATH in the System variables section
  5. Click Edit
  6. Add python's path to the end of the list (the paths are separated by semicolons). For example:
    C:\Windows;C:\Windows\System32;C:\Python27

How to install Matplotlib

1) Download get-pip.py
2) Run file get-pip.py using Python
3) Open cmd.exe (typewrite "cmd" on Search programs and files box)
4) Typewrite the below codes and Enter
(If there is error when running codes, please add Python to Windows Path)
python -m pip install -U pip setuptools
5) Typewrite below codes and Enter
(If there is error when running codes, please add Python to Windows Path)
python -m pip install matplotlib

UDP & TCP Examples

TCP
Server01

import socket
listenport = 5555
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server.bind(("",listenport))
server.listen(5)
print "TCP Sever Waiting for Client on port %d" %listenport
while 1:
    client, address = server.accept()
    print "got connection from ", address
    data = client.recv(512)
    print data
    client.close()

Client01
import socket
msocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
msocket.connect(("127.0.0.1",5555))
msocket.send("Hello World")

Server02
import socket
listenport = 5555
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server.bind(("",listenport))
server.listen(5)
print "TCP Sever Waiting for Client on port %d" %listenport
while 1:
    client, address = server.accept()
    print "got connection from ", address
    while 1 :
        data = client.recv(512)
        client.send(data)
        print "Got: ", data
        if(data=='q' or data=='Q'):
            client.close()
            break;

Client02
use Telnet to test.
วิธีใช้ Telnet

UDP

Server01
import socket
port = 5555
server_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
server_socket.bind(("",port))
print "UDP Server Waiting on port", port
while 1:
    data, address = server_socket.recvfrom(256)
    print "Got Connection from ", address
    print data

Client01
import socket
msocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
msocket.sendto("Hello World",("127.0.0.1",5555))