1 / 45

Network Programming in C #1: Introduction ネットワークプログラミング C 言語 第1回「イントロダクション」

20 11 年秋学期 Rodney Van Meter rdv@sfc.wide.ad.jp. Network Programming in C #1: Introduction ネットワークプログラミング C 言語 第1回「イントロダクション」. Today’s Lecture. This course Goals Outline Staff introductions Basics of networking Exercise. 本講義の位置づけ (2 単位 ). 先端支援系. 創造支援系. 卒業プロジェクト. 創造技法 関連科目 (コンピュータ基礎と

Télécharger la présentation

Network Programming in C #1: Introduction ネットワークプログラミング C 言語 第1回「イントロダクション」

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2011年秋学期 Rodney Van Meter rdv@sfc.wide.ad.jp Network Programming in C#1: IntroductionネットワークプログラミングC言語第1回「イントロダクション」

  2. Today’s Lecture This course Goals Outline Staff introductions Basics of networking Exercise

  3. 本講義の位置づけ(2単位) 先端支援系 創造支援系 卒業プロジェクト 創造技法 関連科目 (コンピュータ基礎と プログラミング) 創造融発 先端開拓 関連科目 (インターネット システム構成法) 先端導入 関連科目 (ネットワーク アーキテクチャ) (インターネット オペレーション) プログラミングスキル 研究会 創造実践 総合講座 先端発見 関連科目(インターネット) シフト系 リフレッシャー科目

  4. Goals Who can take this class? Almost anyone Learn basic structure of network services Programming in C Learn some of the “joseki” (定石) of C Build experience with programming Doing is more important than listening! Software engineering in a team Makefiles, version control, interfaces, modularity, documentation, debugging,

  5. Who’s this for? Who might want to take this class? Almost anyone working around IT Even if your goal is to be a VC or found an NGO, understanding this helps you talk intelligently to networking people Who should take this class? Anyone planning to work in computer systems (network manager/sysadmin, application or OS developer, researcher)

  6. Prerequisites (前提) Minimum Have taken classes in Information Processing (情報処理) 「コン基礎」 or 「インターネット」 Helpful Basics of networks (IP addresses, etc.) Basic programming (editing, compiling, conditionals, loops, functions) Without this, your learning curve will be steep! For those with experience, first half of semester might be a little dull...

  7. English! Lectureswill be in English First step in GIGA Program アイドントスピークイングリシュ! 大丈夫。俺も日本語を話せないから、一緒に頑張ろう! This class is about doing, not listening Lectures are short, most is hands-on TA & SAs all speak 日本語 Slides from prior years (and this year!) available on my web page

  8. この授業の流れ C言語によるプログラミング入門 システムプログラミング ミニプロジェクトのグループ決定 ネットワーク関連のプログラミング ミニプロジェクト成果発表

  9. Class Staff • Faculty • Rodney Van Meter (rdv@sfc.wide.ad.jp) ‏ • Yoshifuji 吉藤 • yoshfuji@wide.ad.jp • Assistants • TA: Takayoshi Mibe • mibe@sfc.wide.ad.jp • SA: Yudai Yamagishi • yummy@sfc.wide.ad.jp

  10. Class Plan Tuesdays, 3rd (13:00-14:30), ο11 First 45 minutes or so: lecture Last 45 min.: hands-one work Last 3 weeks, project work only Hands-on work every week End-of-term presentations: 1/20

  11. I Promise: If you work hard, you will learn more in this class than most others here Many SFC classes are about breadth, this one is about depth To pass, you will have to work hard! Almost every week, you will have to work outside of class TA, SAs and I are available to help English will be a tool, not a barrier

  12. Term Project and Grading Homeworks first half of semester Team project 2nd half of semester Your grade depends primarily on project Team lives & dies together That’s the way it is in life!

  13. Attendance Server Every week, we will record attendance via the network Do “by hand” first few weeks, then via program Protocol simple to start with, more complicated later

  14. Students’ Backgrounds What year? C programming experience? Java programming experience? Classes? インターネットオペレーション インターネット ネットワークアーキテクチャ システムプログラミング

  15. C Background C programming experience? Understand edit-compile-debug cycle? What environment (Unix, Windows, IDE, make)? Functions? Pointers (difficult concept, incredibly important and useful)? Memory management (hard!)?

  16. 今期の授業スケジュール(予定) 第1回 9/30:Hello World! 第2回 10/7:Loops and control flow 第3回 10/14:Data structure and pointers 第4回 10/21:Pointers and Memory Management 第5回 10/28: File I/O 第6回 11/4:IP Networking Basics‏ 第7回 11/11:Basic Socket Programming 1‏ 第8回 11/25:Basic Socket Programming 2 第9回 12/2:Naming: DNS Requests 第10回 12/9:RPC: Remote Procedure Calls 第11回 12/16:Project Programming 1 第12回 1/6:Project Programming 2 第13回 1/13:Project Programming 3 第14回 1/20:Project Demonstration

  17. Programming Environment CNS Linux:ccx00,ccx01 Login via SSH http://itc.sfc.keio.ac.jp/ssh/ PuTTY: http://www.chiart.greenend.org.up/~sgtathm/putty/ http://hp.vector.co.jp/authors/VA024651/PuTTYkj.html Submit homework via SFS

  18. Programming Environment (2)‏ OK to use your own PC Windows: cygwin 注意:IPv6は動かないかも IPv6 important in this class, cygwin support still weak? Linux, BSD, Mac: native environment

  19. ここから本編~ネットワークの基礎

  20. Basics of Network Architecture Protocols Layered protocol model What’s a network application?

  21. Protocol • In order for two computers to talk, they have to share a language and follow a set of rules: a protocol is what they promise each other • Without a protocol, they can’t talk to each other!

  22. Humans Use Protocols 電話の例 1) 受話器を上げる • One speaking English, the other Japanese (probably) doesn’t work • On phone, start with 「もしもし,xxです」 or “Hello” • Same for computers • UNIX-Windows間の通信 • 無線-有線間の通信 2) 電話番号を入力 5) 会話する 6) どちらかが受話器を置く 3) 着信を通知する 4) 受話器を上げる 7) 回線が切れる

  23. OSI Layered Model アプリケーション層 Data プレゼンテーション層 Application Layer セッション層 Presentation Layer トランスポート層 Session Layer ネットワーク層 Packet Transport Layer データリンク層 Network Layer Frame 物理層 Data Link Layer Signal Physical Layer ・各プロトコルの関係を階層構造でモデル化

  24. 1) Physical Layer Defines physical characteristics Signal strength/voltage, how to make numbers, etc. 電波強度、符号変調方式 Media Optical fiber, copper wire, electrical lines, satellite, radio... Usually standardized by some group(ITU-T,ISO,…)‏ 規格 X.25,IEEE,ATM,ISDN… 光)SONET,FDH…

  25. Data Link Layer 物理的な通信媒体に対応した、フレームをやり取りするためのプロトコルを規定する層 同期,送信権の制御 CSMA/CD 識別 MAC Address 誤り検出 CRC Checksum

  26. 3) Network Layer Independent of physical layer, how two hosts on Internet transfer data End-to-End Path control (routing)‏ IPv4,IPv6 Generally requires globally unique address

  27. 4) Transport Layer Layer that processes in a host usually use TCP,UDP Most protocols divide service by PORT

  28. 5) Session Layer One “session” – start to finish of communication between two apps Cooperatively managed between sender and receiver Generally handled by applications Most Internet apps one “session” is one transport-level connection

  29. 6) Presentation Layer セッションでやり取りされるデータの表現方法や符号化、暗号化などを規定する層 Byte Order (“Endianness”) Least/Most Significant Bit (LSB/MSB)‏ Htonl(), Htons()‏ Usually handled by applications

  30. 7) Application Layer Agreed upon by two applications e.g., what Email contents look like (headers, etc.) Most applications handle layers 5 and up themselves

  31. アプリケーション層Application Layer アプリケーション層Application Layer トランスポート層Transport Layer トランスポート層Transport Layer ネットワーク層Network Layer ネットワーク層Network Layer ネットワーク層Network Layer データリンク層Data Link Layer データリンク層Data Link Layer データリンク層Data Link Layer 物理層Physical Layer 物理層Physical Layer 物理層Physical Layer Internet Layered Model エンドノード 中継ノード エンドノード 送信元から中継ノード(ルータ)を通ってあて先に到達する

  32. アプリケーション層Application Layer プレゼンテーション層Presentation Layer セッション層Session Layer トランスポート層Transport Layer ネットワーク層Network Layer データリンク層Data Link Layer 物理層Physical Layer OSI Model & Internet Architecture Web XML Webサービス Email NNTP ・・・ Messaging File transfer File sharing TCP UDP IP Ethernet xDSL Optical fiber 無線LAN (WLAN) 32

  33. アプリケーション アプリケーション TCP TCP IP IP Ethernet/100M Ethernet/100M CAT5e CAT5e プロトコルスタックとカプセル化 • 送信側 • 各層がそれぞれ必要な情報(ヘッダ)を付加して下層へ渡す • 受信側 • 各層はヘッダの情報をもとに処理を行い,そのヘッダ部分を取り除いて上層へ渡す 例:HTTPヘッダ データ データ TCPヘッダ IPヘッダ Ethernet Frame 信号へ 送信側 受信側

  34. ネットワークアプリケーションとは? process process process process TCP UDP transport layer ICMP IP IGMP network layer ARP RARP data link layer hardware interface media

  35. ネットワークアプリケーションとは?(IPv6) process process process process TCP UDP transport layer ICMPv6 IPv6 MLD network layer NDP (ICMPv6) NDP (ICMPv6) data link layer hardware interface media

  36. ここから実習~C言語に触れてみる

  37. Practice Getting started login to CNS via SSH Create “Hello world” program with Makefile “こんなのできるぜ”というたしなみのある人は帰っていいよ Once this is done, you can go home!

  38. 今日の環境 CNS環境 Linux:ccx00,ccx01 sshして上記のホストにログイン http://itc.sfc.keio.ac.jp/ssh/ PuTTY: 自分のホームディレクトリにファイルを置く

  39. はろーわーるど ???.c というファイル名 gccコマンド include printf a.out などのおまじないを体験してみる

  40. hello.cの例 #include <stdio.h> int main (int argc, char* argv[]) { printf("%s\n", "Hello World!"); } #include <stdio.h> main(){ printf(“Hello World!\n”); } →gcc hoge.c → ./a.out

  41. Compiling gcc hoge.c a.outというファイルが生成される または gcc –o hoge hoge.c hogeというファイルが生成される

  42. Makefile 再コンパイルの煩雑さを解消 コンパイル時は make と打つだけ 基本文法 ターゲット:依存するファイル <tab>コマンド

  43. Makefileの例 all: program program : source1.o source2.ogcc -o program source1.o source2.o source1.o : source1.cgcc -c source1.c source2.o : source2.cgcc -c source2.c

  44. Makefileの簡素化 .cから.oファイルの生成ルール all : source1.o source2.o gcc -o program source1.o source2.o コンパイルオプションの変数化 <command> %gcc -Wall -g -c source1.c <Makefile> CFLAGS = -Wall gcc ${CFLAGS} -c source1.c

  45. Makefile: hello.cへの適用例 all: hello hello: hello.o gcc -o hello hello.o hello.o: hello.c gcc -c hello.c

More Related