csp_07-08_net

Download Report

Transcript csp_07-08_net

Cross-sensorial processing
– MED7
CSP07-08
- Implementing a network
Implementing a network
Lecturer:
Smilen Dimitrov
1
CSP07-08 - Implementing a network
Introduction
•
•
•
•
•
The immobot base exercise
Work on the network
Goal – implement a simple network
Now not concerned with
rest of system
Setup:
– 2 PCs
– Switch or router
2
CSP07-08 - Implementing a network
Setup
•
Setup for a PC:
1. Microsoft Visual Studio
2. Max/MSP/Jitter (for testing)
•
This time we only discuss basics of network implementation, so we will
mostly work outside of the scope of the base exercise system
•
Needed because we need to send the results from audio and video
processing algorithms (in Max/MSP) to an application in Virtools on a third
PC
•
Network code will be ported in the context of the base exercise next time
3
CSP07-08 - Implementing a network
Goal of the network implementation
•
4
CSP07-08 - Implementing a network
Socket approach - Server/client architecture
•
A network server or client functionality is implemented using sockets
– in both cases, the sockets can read and write data
– the difference is mostly in the roles in the interaction, during phase of
initiation of communication
•
Definitions from: http://en.wikipedia.org/wiki/Internet_socket
•
An Internet socket (or commonly, a socket or network socket), is a
communication end-point unique to a machine communicating on an
Internet Protocol-based network, such as the Internet.
•
By Cisco definition, "The combination of an IP address and a port number is
referred to as a socket."
5
CSP07-08 - Implementing a network
Socket approach - Server/client architecture
•
Operating systems combine sockets with a running process or processes
(which use the socket to send and receive data over the network), and a
transport protocol (i.e. TCP or UDP) with which the process(es)
communicate to the remote host.
•
Usually sockets are implemented over TCP but this is not required.
•
The concept of a socket is an entity that implements an API, regardless of
the implementation. Two widely used Internet socket types are:
– Datagram sockets, which use UDP
– Stream Sockets, which use TCP
•
In contrast with the use of TCP connections directly, using sockets makes a
distinction between client and server, and it is able to implement a queue of
clients over a given server socket. Sockets usually are implemented by a
library (such as Berkeley sockets or Winsock)
6
CSP07-08 - Implementing a network
Socket approach - Server/client architecture
•
The question is what kind of a network to implement between the three
computers, TCP or UDP?
•
We would want to stream data in real time – that means specific data, which
in time comes one after another, should also arrive one after another in the
network
•
TCP (Transmission Control Protocol) is a reliable protocol that guarantees
that packets sent in one order, arrive in the same order -
•
UDP (User Datagram Protocol) is an unreliable protocol – it does not
guarantee the order of the packets (although, for a wide bandwidth local
network, without traffic to the Internet, in most cases, packets will arrive in
order); but it can do multicast.
•
Thus, we will implement a TCP server / client network here.
7
CSP07-08 - Implementing a network
Socket approach - Server/client architecture
•
General server / client model
•
TCP – Connection oriented protocol – establishing communication analogue
to a phone call
•
The role of the
– client socket is to send a request – upon which a communication link is
established and data is exchanged (the client is the one that makes a
telephone call - “dials a number”)
– server socket is to wait for requests (the server “waits by the telephone”
and picks up the handle when the client rings).
8
CSP07-08 - Implementing a network
Socket approach - Server/client architecture
•
•
Our 3 PC system would be connected on a local network, using a switch or
router
On this network, the PCs are assigned local IP network addresses
(192.168.*.*)
the sockets themselves (running in the PCs) are bound to a port number.
•
How to set up the client/server architecture?
•
9
CSP07-08 - Implementing a network
Socket approach - Server/client architecture
•
Our 3 PC system is easy to conceptualize in terms of network needs:
– PC 1 and 2 perform processing on data incoming from sensors, so they
need to send data to the third PC
– PC 3 needs to receive data from the first two PCs and perform
additional processing
•
This however does not determine the client-server roles
•
Good starting point is to see into the already available network objects in
Max/MSP – then it is easier to decide on the architecture
•
First we look into the OSI network model
10
CSP07-08 - Implementing a network
Layers in OSI model
•
•
OSI model never got fully implemented
still a useful academic metaphor for abstracting different stages in the
computer networking process.
11
CSP07-08 - Implementing a network
Layers in OSI model
•
Layer 1 - physical layer, which defines all electrical and physical
specifications for devices
•
Layer 2 - data link layer, which also operates on a physical level – within the
networking card – so it uses hardware networking addresses (MAC or Media
Access Control addresses). Ethernet is a layer two protocol.
– This is the layer at which bridges and switches operate. Connectivity is
provided only among locally attached network nodes.
•
Layer 3 - network layer. Performs network routing, flow control,
segmentation/desegmentation, and error control functions. The protocol that
operates on this level is called Internet Protocol, or IP.
– This is the layer at which router operates – makes Internet possible
12
CSP07-08 - Implementing a network
Layers in OSI model
•
Layer 4 - transport layer- provides transparent transfer of data between end
users.
– This is the layer at which sockets are defined
– Sockets can be connection-oriented (stream sockets - TCP) or
connectionless (datagram sockets - UDP), and each has their own
protocol
– Winsock, as a library that we can use to program the socket functionality
with Windows, is an interface standard between applications (layers 5
and above) and the transport (layer 4)
•
Layer 5 – session layer - provides the mechanism for managing the dialogue
between end-user application processes
– establishes checkpointing, adjournment, termination, and restart
procedures
– is responsible for setting up and tearing down TCP/IP sessions.
– (part of specific application code)
13
CSP07-08 - Implementing a network
Layers in OSI model
•
Layer 6 – presentation layer - deals with data representation and encryption.
– this layer encompasses the job of deciding how the data stream will be
formatted - and thus we specify how the data is coded and decoded.
•
Layer 7 - application layer. This layer interfaces directly to and performs
common application services for the application processes.
– This is the layer at which HTTP (Hyper Text Transfer Protocol) is
defined – it represents a layer seven protocol
•
Comparison between TCP stack
and OSI model layers:
14
CSP07-08 - Implementing a network
Layers in OSI model
•
OSI Layer comparison (from a project with custom network development):
15
CSP07-08 - Implementing a network
Networking capabilities of Max/MSP
•
There are no native objects that provide socket connectivity in Max/MSP
•
There are some objects made by Olaf Matthes, which can be downloaded
on the web
– The first is a pair of objects known as netsend and netreceive
– There is another object called flashserver
16
CSP07-08 - Implementing a network
Networking capabilities of Max/MSP
•
The pair of objects known as netsend and netreceive
– Two boxes are meant for communication between two Max/MSP
programs on different PCs on a network
– they support both the TCP and UDP mode.
– netreceive represents a listening socket (server), whereas
– netsend initiates connections - so it is a client.
17
CSP07-08 - Implementing a network
Networking capabilities of Max/MSP
•
The object known as flashserver
– meant for communication between Max/MSP program and Adobe
(Macromedia) Flash
– TCP/IP socket connection – listening network socket; a socket server
– Maximum number of possible clients is 256
– More suitable?
•
We will try to test these Max/MSP networking objects
18
CSP07-08 - Implementing a network
Testing connections between PCs (Windows)
•
•
•
Using ipconfig to retrieve the PC addresses
Testing with ping
Handling the firewall
19
CSP07-08 - Implementing a network
Testing the netsend, netreceive and flashserver objects
•
In the previous discussion we determined that
– netsend is a client which can only send
– netreceive is a server (listening socket) which can only receive
– flashserver is a server (listening socket) which can both send and
receive
•
Testing
– Netsend with netreceive
– Netsend with flashserver
– telnet (as client) with flashserver
– Netsend with flashserver, captured with Ethereal
20
CSP07-08 - Implementing a network
Implementing a receiver
•
We could interface with any of the Max/MSP networking objects.
•
Since we need to send from Max, we can use either netsend or flashserver.
– If we use netsend, as it is a client, we would correspondingly need to
program a server.
– If we use flashserver, as it is a server, we would correspondingly need
to program a client.
•
Here we will try both approaches as standalone Windows executables –
programmed in C/C++, using the Winsock library.
– Server receiver – test with netsend
– Client receiver – test with flashserver
•
Netsend handles quick data better – so will use that, and server receiver
– Two-thread server receiver – test with two netsend clients
21