60
Process Diagram of Server Program
2.
Client
It is easier to create a TCP client than to do a server. Take the following pseudocode:
c
=
socket
(
)
# Create a client socket.
c
.
connect
(
)
# Try to connect a server.
comm_loop
:
# Communication loop.
c
.
send
(
)/
c
.
recv
(
)
# Dialog (sending out and receiving data)
c
.
close
(
)
# Close the client socket.
As mentioned above, all sockets are created via the function
socket.socket( )
. Then, the
function
connect( )
can be called to connect the server. After the connection is built, the
dialog between the client and the server is enabled. When the dialog ends, the client can
close the socket and the connection.
Introduction of Tkinter
Developed based on Tkinter, our client program carries
graphical interfaces. Tkinter is a GUI
widget set for Python. We can develop application programs with graphical interfaces fast
by Python language based on it. It is quite easy to use Tkinter. All you have to do is to
import
the module into Python.
To create and run a GUI program, take the following steps:
a)
Import the Tkinter module (by
import Tkinter
or
from Tkinter import *
).
b)
Create a top window object to contain the whole GUI program.
SunFounder