Socket Programming
BUPT-SE Spring, 2012
Basic Concepts in NP
• Introduction to Network Programming • Program Developing • Basic Concepts
– Process – File Descriptor – System Call – Signal
2
1
2012/4/13
Program Developing - Phases
Begin Requirement Analysis Preliminary Design Investigate the requirements Select or develop an algorithm to solve the problem Define data structure Detailed Design Define the format of input and output Draw a flow-chart and module design Input and edit the source program Coding Compile it no errors Testing Running and testing it successful End
3
errors unsuccessful
Program Developing - skills
• Programming style
– – – – ident, remarks, variable names, http://en.wikipedia.org/wiki/Indent_style http://www.cprogramming.com/tutorial/style.html http://courses.cs.vt.edu/~cs2604/fall01/standards.html
• Editor
– vi, a very powerful full screen editor – pico, an utility with Linux – http://www.reallylinux.com/docs/editors/editor.shtml
– http://pangea.stanford.edu/computing/unix/editing/editorchoices.php
• Related Linux/Unix command
– http://www.cs.cmu.edu/~gilpin/tutorial/
• Backup your program is important!
4
2
2012/4/13
Program Developing – C Compiler in Linux
• cc
– Example: % cc test1.c -o test – test1.c : program to be compiled – -o : specify the name for running program
• gcc
– Example: % gcc test1.c –o test
5
Program Developing – debugger in Linux
• • •
gdb [options] [executable-file [core file or process-id]] Example: % gdb test1 gdb Command list
– – – – – – – – – – – – file : load the program for debugging kill : stop the program for debugging list : list the source code of the program for debugging break : set a break point in the source program run : run the program to be debugged next : execute a single line of the program, but not go into it step : execute a single line of the program, but go into it quit : quit the gdb to shell print : display the