Slide design: Dr. Mark L. Hornick

Slides:



Advertisements
Similar presentations
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Advertisements

Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
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.
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Today Networking in Linux/C Lab Eclipse cross-compiling Measuring latency of 100% CPU busy-wait polling Sleeping busy-wait polling Interrupt-driven response.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
Socket Programming Based on tutorial prepared by EUISOK CHUNG CS3320 Spring2008.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Operating Systems Chapter 9 Distributed Communication.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Week 13 - Monday.  What did we talk about last time?  Low level file I/O practice  File systems.
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.
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.
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
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.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
Introduction to Sockets
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
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.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level connection.Establishing.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
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.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
Socket Programming Client/Server.
Slide Style & Content: Dr. Schilling
Slide design: Dr. Mark L. Hornick
Sockets and Beginning Network Programming
Jim Fawcett CSE 681 – Software Modeling & Analysis Fall 2002
UNIX Sockets COS 461 Precept 1.
Slide design: Dr. Mark L. Hornick
Week 13 - Friday CS222.
Socket Programming in C
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Transport layer API: Socket Programming
Things that are nice to know when you’re doing this project
TCP Sockets Programming
Advanced Network Programming spring 2007
TCP/IP Socket Programming in C
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Slide design: Dr. Mark L. Hornick
Outline Communications in Distributed Systems Socket Programming
Sockets.
Today’s topic: Basic TCP API
Jim Fawcett CSE 681 – Software Modeling & Analysis Summer 2003
Presentation transcript:

Slide design: Dr. Mark L. Hornick SE3910 10/22/2017 SE3910 Week 3, Class 1 Today I/O Circuits Networking in C on a Linux machine In Lab: Quiz C review: Pointers, Dereferencing, etc. Networking in C – don’t need to memorize API… SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder Dr. Josiah Yoder

CS2852 10/22/2017 Sockets A socket is defined as an endpoint for communication – socket() man page Socket Address: Transport-level Protocol: (e.g. TCP or UDP) Port 1625 Host IP address:161.25.19.8 Full address: udp://161.25.19.8:1625 Communication is between a socket on the client and a socket on the server. Draw picture as in slides Note. Would not actually type udp://…. Into a browser. Dr. Yoder

TCP Sockets TCP also uses client’s IP and port to distinguish sockets Client socket – endpoint on client Listenening socket – endpoint on server with address to accept new connections Data socket – endpoint on server dedicated to a specific client-server connection SE-2811 Dr.Yoder

Well-Known Ports 0 – 1023 Well known ports 7 Echo 20 ftp CS2852 10/22/2017 Well-Known Ports 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 SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Yoder

Security Now plug A recent Security Now broadcast mentioned a server that intended to listen only on localhost, but due to configuration error, the port became open for the whole network. A worm then finds this open port and infects the server… Details: https://www.grc.com/sn/sn-598.txt (Search for “worm”) SE-2811 Dr.Yoder

Port and Address in POSIX C SE3910 10/22/2017 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 (for IPv4 sockets) These are defined in systypes.h, I think 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 */ }; struct in_addr { n_addr_t s_addr; } SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Josiah Yoder

The socket() system call creates a new socket. SE3910 10/22/2017 The socket() system call creates a new 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-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Josiah Yoder

Server: Binding to a socket 10/22/2017 Server: Binding to a socket bind() system call binds a socket to an address Takes three arguments socket file descriptor socket 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-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Josiah Yoder

Server: Listen & Accept 10/22/2017 Server: Listen & Accept 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() Blocks until a client connects to a server SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Josiah Yoder

Client: Connect Client side connect() SE3910 10/22/2017 Client: Connect Client side 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-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Josiah Yoder

SE3910 10/22/2017 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. write() Writes data to the buffer SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Josiah Yoder

See example code server.c client.c Near middle of Lab 4 webpage. Dr.Yoder

SE3910 10/22/2017 References http://pubs.opengroup.org/onlinepubs/007908799/xns/syssocket.h.html syssocket.h http://pubs.opengroup.org/onlinepubs/007908799/xsh/unistd.h.html unistd.h http://pubs.opengroup.org/onlinepubs/7908799/xsh/systypes.h.html systypes.h – for xxxx_t SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Josiah Yoder

Slide design: Dr. Mark L. Hornick SE3910 10/22/2017 SE3910 Week 3, Class 3 Today More on networking See also other slides In Lab: Quiz C review: Pointers, Dereferencing, etc. Networking in C – don’t need to memorize API… Data rates Another circuit with a switch? SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder Dr. Josiah Yoder

SE3910 10/22/2017 Subnets For two nodes to communicate on a network, they must be on the same IP subnet For example, in lab, the switches set up a 192.168.1.X subnet. The subnet mask has 1's for the subnet part, and zeros for the individual node's part, e.g. 255.255.255.0 So for the address 192.168.1.100, the subnet part is 192.168.1. and the individual computer's part is .100 Dr. Josiah Yoder

SE3910 10/22/2017 Choosing an IP address All computers can choose their own addresses, as long as they choose an address in the same subnet The switch will act as a DCHP server, and assign IP addresses to any node acting as a DHCP client Your windows laptop, the VM, and the BeagleBone Black can all use either of these approaches SE-2811 Dr.Yoder Dr. Josiah Yoder

SE3910 10/22/2017 Bridging networks In bridging mode, the host helps the virtual machine appear to the outside world through one of its adapters. If the VM talks, the host will send packets with the VM's IP. If the host itself talks, it will send packets with its own IP To connect your VM to the internet, connect it to an interface connected to the internet To connect your BB to the internet, plug it into a wired network connection Dr. Josiah Yoder

NAT – Network Address Translation In NAT mode, the host plays the role of the virtual machine to the outside world, perhaps through all of its adapters? If the VM talks, the host will send packets with the host’s IP. If the host receives messages bound for a TCP port established by the VM, it will send it to the VM. Otherwise, it will send it to the host machine. This might be why NAT works better for pinging the BB or google from the VM SE-2811 Dr.Yoder

NAT capture On the VM: On the host: The same messages, captured by both host and client machine SE-2811 Dr.Yoder

SE3910 10/22/2017 Spring 2017 Everyone who has used the NAT approach has been able to ping the BB (BeagleBone) from the VM through the USB I recommend doing this for prelab. If that fails, I recommend using the shared folder to access your VM files from off the VM Then use the host to copy them through USB to the BB. SE-2811 Dr.Yoder Dr. Josiah Yoder

Places on campus with Wired internet connections SE3910 10/22/2017 Places on campus with Wired internet connections Some parts of CC third floor (the Mage corner) Perhaps some rooms ground CC Some SDL cubicles Dorms – except for SMTP Science building S365 Apartment (off-campus) SE-2811 Dr.Yoder Dr. Josiah Yoder

Stopped Here Spring 2017 SE-2811 Dr.Yoder

I was asked this question in an interview today…. SE3910 10/22/2017 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. http://stackoverflow.com/questions/5269535/java-threads-vs-pthreads SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Josiah Yoder

Threading – pthreads Java Pthreads java.lang.Thread SE3910 10/22/2017 Threading – pthreads Java Pthreads java.lang.Thread #include <pthread.h> No external jar needed link 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(…) View links in class Dr. Josiah Yoder

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-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling

Threading – pthreads (updated with links) CS2852 10/22/2017 Threading – pthreads (updated with links) Java Pthreads Object o; o.notify(); phread_cond_t c = PTHREAD_COND_INITIALIZER; pthread_cond_broadcast(c); o.wait(); pthread_cond_wait(c,m); phtread_cond_signal(c); o.notifyAll(); phtread_cond_broadcast(c); View links in class. See Java coding example NotifyWaitExample Caveat: “POSIX threads can wait at condition variables of a greater generality than available in Java, but the corresponding queues may be leaky.” http://wimhesselink.nl/pub/whh241b.pdf SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Dr. Yoder

Possibly Fun Very simple C++ wrapper for pthreads http://www.cs.utexas.edu/users/lavender/courses/cs345/lectures/CS345-Lecture-09.pdf notify/wait – example comparison with Java and pthreads http://wimhesselink.nl/pub/whh241b.pdf Compares create for Java, pthreads, and Win32 threads http://cs.millersville.edu/~csweb/lib/userfiles/9ThreadsII.pdf SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling

Certainly fun (Dr. Taylor’s Reviews) http://msoe.us/taylor/tutorial/ce2810/functionpointers Function Pointers http://msoe.us/taylor/tutorial/ce2810/csimilar C/C++/Java http://msoe.us/taylor/tutorial/ce2810/ooc Object-Oriented C SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling

Other references http://granite.sru.edu/~whit/cpsc464/Notes/figs/02-14.jpg Simple pthread chart From http://granite.sru.edu/~whit/cpsc464/Notes/ch2.html https://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Fapis%2Fusers_75.htm IBM example of using pthread_cond_init SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling

Standards http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread.h.html pthead.h http://pubs.opengroup.org/onlinepubs/7908799/xsh/systypes.h.html systypes.h – for xxxx_t SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling

Slide design: Dr. Mark L. Hornick References EB: Derek Malloy, Exploring Beaglebone, Wiley, 2015 Laplante and Ovaska, Real-Time Systems Design and Analysis, Fourth Edition, Wiley, 2012 SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder