Today Networking in Linux/C Lab Eclipse cross-compiling Measuring latency of 100% CPU busy-wait polling Sleeping busy-wait polling Interrupt-driven response.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Sockets: Network IPC Internet Socket UNIX Domain Socket.
Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Sockets Programming CS144 Review Session 1 April 4, 2008 Ben Nham.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Tutorial 8 Socket Programming
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Introduction to Project 1 Web Client and Server Jan 2006.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Operating Systems Chapter 9 Distributed Communication.
Assignment 3 A Client/Server Application: Chatroom.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
SE3910 Week 2, Class 1 Today Basic Circuits Other ??? Tomorrow Lab 2, S365 (Complete prelab BEFORE) Thursday See ScheduleSchedule SE-2811 Slide design:
Sirak Kaewjamnong Computer Network Systems
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
SE-3910 Real-time Systems Week 2, Class 2 – Return stuff, New HW Assignment! – Quiz! (Possibly with review) Ohm’s Law Kirkhoff’s Current Law Switches Using/reading.
Today Networking in Linux/C Lab Eclipse cross-compiling Measuring latency of 100% CPU busy-wait polling Sleeping busy-wait polling Interrupt-driven response.
Remote Shell CS230 Project #4 Assigned : Due date :
Today Quiz Multithreading Options Qt socket buffers between threads Quiz today & Tuesday in lab SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
SE-3910 Real-time Systems Week 4, Class 1 – Quick-Quiz (Ungraded!) – Graded quiz tomorrow – Review coding in C – Libraries Threading Library in C Networking.
University of Calgary – CPSC 441.  A socket is an interface between the application and the network (the lower levels of the protocol stack)  The application.
Introduction to Socket
Today C/C++:.h/.cpp; compiling and linking Fourier Transform (corrected) Nyquist Theorem Audio sampling rates SE-2811 Slide design: Dr. Mark L. Hornick.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
Today Nervous System Response Time SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 3, Class 2.
Introduction to Sockets
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
Today Return Quiz First release of final project template Multithreading Options Qt socket buffers between threads Tomorrow: Quiz Interthread communication.
Today Final Project “Preview” Real-time concurrency Multithreading Options pthreads qthreads GPIO.h & GPIO.cpp Quiz tomorrow & Tuesday in lab SE-2811 Slide.
Today Return Quiz First true release of final project (Lab 8) Multithreading Options Qt socket buffers between threads SE-2811 Slide design: Dr. Mark L.
In unistd.h : int gethostname(char * name, int maxlen) Purpose : Find the computer's name.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Slide design: Dr. Mark L. Hornick
Socket Programming Client/Server.
Slide Style & Content: Dr. Schilling
Slide design: Dr. Mark L. Hornick
Transport layer API: Socket Programming
Slide design: Dr. Mark L. Hornick
TCP Sockets Programming
Advanced Network Programming spring 2007
TCP/IP Socket Programming in C
Slide design: Dr. Mark L. Hornick
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Slide design: Dr. Mark L. Hornick
in unistd.h: int gethostname(char * name, int maxlen)
Outline Communications in Distributed Systems Socket Programming
Sockets.
Today’s topic: Basic TCP API
Presentation transcript:

Today Networking in Linux/C Lab Eclipse cross-compiling Measuring latency of 100% CPU busy-wait polling Sleeping busy-wait polling Interrupt-driven response Network transmission SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 3, Class 3

Ex: What is the resistance of this resistor? 2

Ex: GPIO safety Considering the resistor on the previous slide, is it large enough to not damage a GPIO pin configured as output, if the resistor ties the output to ground? Sourcing limit: 4mA Sinking limit: 8mA Voltage: 3.3 V SE-2811 Dr.Yoder 3

Ex: What’s wrong with this circuit? (The worst thing) SE-3910 Dr.Yoder 4

Sockets 5 A socket is defined as an endpoint for communication Concatenation of IP address, port – Transport-level Protocol: (e.g. TCP or UDP) – Port 1625 – Host IP address: Socket :1625 TCP also uses client’s IP and port to distinguish sockets Communication consists between a pair of sockets

Well-Known Ports SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 6 0 – 1023 Well known ports 7 Echo 20 ftp 22 ssh 25 smtp 37 time 70 gopher 79 finger 80 http 666 doom 992 telnet 1024 Registered Ports 1234 Mercurial / git 1309 Altera Quartus 1417 – 1420 Timbuktu Service 1500 IBM Tivoli 1534 Eclipse Agent Discovery Etc

Port and Address in POSIX C in_port_t An unsigned integral type of exactly 16 bits. in_addr_t An unsigned integral type of exactly 32 bits. These are defined in systypes.h, I think SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 7 struct in_addr { n_addr_t s_addr; } istruct sockaddr_in { short sin_family; /* must be AF_INET */ u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; /* Not used, must be zero */ };

The socket() system call creates a new socket.socket 3 arguments Address domain of the socket.  AF_UNIX or AF_INET Type of socket.  SOCK_STREAM or SOCK_DGRAM. Protocol.  Usually 0 SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 8

Binding to a socket bind() system call binds a socket to an address bind Takes three arguments socket file descriptor address to which is bound size of the address to which it is bound Just like in Java, only servers need to do this (???) SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 9

Listen & Accept SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 10 listen() listen Allows the process to listen for connections to a given socket Two arguments Socket file descriptor Number of queues that can be waiting accept() accept Blocks until a client connects to a server

Connect Client side connect() connect int socket – file descriptor for the socket const struct sockaddr *address – the address to connect to socklen_t address_len – len of address returns 0 upon successful completion SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 11

Read & Write read() attempts to read nbyte bytes of data from the object referenced by the descriptor fd into the buffer pointed to by buf. read write() write Writes data to the buffer SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 12

References 799/xns/syssocket.h.html 799/xns/syssocket.h.html syssocket.h 799/xsh/unistd.h.html 799/xsh/unistd.h.html unistd.h 9/xsh/systypes.h.html 9/xsh/systypes.h.html systypes.h – for xxxx_t SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 13

I was asked this question in an interview today…. "When we create a thread with pthread_create() (POSIX Threads), the thread starts on its own. Why do we need to explicitly call start() in Java. What is the reason that Java doesnt start the thread when we create an instance of it." I was blank and interviewer was short of time and eventually he couldnt explain the reason to me. a-threads-vs-pthreads SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 14

Threading JavaPthreads java.lang.Thread#include No external jar neededlink with -pthread Thread t = new Thread(r) t.start(); pthread_create(t,r,sr,a) interface Runnable { void run(); } Parameter: void* (*sr) (void *) t.join();pthread_join(*t, &p) Object o;pthread_mutex_init(m,null) synchronized(o) { … } … /* Garbage coll. */ pthread_mutex_lock() … pthread_mutex_destroy() SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 15

From Taylor’s We can declare a function pointer by: uint8_t (*min)(uint8_t, uint8_t); We can assign a function pointer to point to an actual function by: uint8_t minimum(uint8_t num1, uint8_t num2) { return num1 < num2 ? num1 : num2; } min = &minimum; We can use it to call minimum using either of the following ways: uint8_t answer = min(3, 8); uint8_t answer = (*min)(3, 8); SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 16

Threading Javapthreads Object o; o.notify(); phread_cond_t c = PTHREAD_COND_INITIALIZER; pthread_cond_broadcast(c); o.wait();pthread_cond_wait(c,m); o.notify();phtread_cond_broadcast(c); SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 17 Caveat: See

Possibly Fun Very simple C++ wrapper for pthreads cs345/lectures/CS345-Lecture-09.pdf cs345/lectures/CS345-Lecture-09.pdf notify/wait – example comparison with Java and pthreads Compares create for Java, pthreads, and Win32 threads adsII.pdf adsII.pdf SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 18

Certainly fun (Dr. Taylor’s Reviews) ointers ointers Function Pointers C/C++/Java Object-Oriented C SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 19

Other references s/02-14.jpg s/02-14.jpg Simple pthread chart From m0/index.jsp?topic=%2Fapis%2Fusers_75. htm 1m0/index.jsp?topic=%2Fapis%2Fusers_75. htm IBM example of using pthread_cond_init SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 20

Standards 9/xsh/pthread.h.html 9/xsh/pthread.h.html pthead.h 9/xsh/systypes.h.html 9/xsh/systypes.h.html systypes.h – for xxxx_t SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 21

Some Technical Goals How does one control the speed of a motor? How does one change the brightness of a light-bulb? SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 22

Pulse-Width-Modulation … in traffic SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 23

Pulse-width modulation terminology SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 24 Determine the duty cycle (D) Multiply the duty cycle by the peak volta ge (V p )

In-class exercise How can you control the brightness of an LED, using tools we have discussed so far? How would you accomplish this if you went into lab right now? SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 25

Advantages of Pulse-Width Modulation Click to add text SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 26

Muddiest Point Wait for the slides, or follow this link to answer both questions at once: SE-2811 Dr.Yoder 27

SE-2811 Dr. Josiah Yoder 28

SE-2811 Dr. Josiah Yoder 29

References EB: Derek Malloy, Exploring Beaglebone, Wiley, 2015 SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 30