• Aucun résultat trouvé

[PDF] Support de cours détaillé d'introduction à la programmation réseau en Java

N/A
N/A
Protected

Academic year: 2021

Partager "[PDF] Support de cours détaillé d'introduction à la programmation réseau en Java"

Copied!
93
0
0

Texte intégral

(1)

Cours JAVA :

La programmation réseau en Java.

Version 1.01

Julien Sopena

1

1

julien.sopena@lip6.fr

Équipe REGAL - INRIA Rocquencourt

LIP6 - Université Pierre et Marie Curie

(2)

Grandes lignes du cours

Une abstraction des protocoles réseau

Gestion des addresses réseau en Java

Le sockets TCP

(3)

Outline

Une abstraction des protocoles réseau

Gestion des addresses réseau en Java

Le sockets TCP

(4)

Quel niveau d’abstraction pour le réseau ?

Les 7 couches du modèle OSI

Couche 7 -

Applicative

: Les logiciels (ex : NFS)

Couche 6 -

Présentation

: Représentation des données (ex : XDR)

Couche 5 -

Session

: Établissement et maintient des sessions (ex : RPC)

Couche 4 -

Transport

: Liaison de bout en bout (ex : UDP, TCP, ...)

Couche 3 -

Réseau

: Adressage et routage entre machines (ex : IP)

Couche 2 -

Liaison

: Gestion des envois point à point (ex : Ethernet)

Couche 1 -

Physique

: Support de transmission

Les Sockets Java offrent une abstraction du réseau au niveau des

couches Transport (4) et Réseau (3). Java introduit donc

différentes classes correspondant aux protocoles abstraits : TCP ou

UDP.

(5)

Quel niveau d’abstraction pour le réseau ?

Les 7 couches du modèle OSI

Couche 7 -

Applicative

: Les logiciels (ex : NFS)

Couche 6 -

Présentation

: Représentation des données (ex : XDR)

Couche 5 -

Session

: Établissement et maintient des sessions (ex : RPC)

Couche 4 -

Transport

: Liaison de bout en bout (ex : UDP, TCP, ...)

Couche 3 -

Réseau

: Adressage et routage entre machines (ex : IP)

Couche 2 -

Liaison

: Gestion des envois point à point (ex : Ethernet)

Couche 1 -

Physique

: Support de transmission

Les Sockets Java offrent une abstraction du réseau au niveau des

couches Transport (4) et Réseau (3). Java introduit donc

(6)

La notion de mode de connecté

Définition

En

mode connecté

, la communication entre un client et un serveur est

pré-cédée d’une connexion et suivie d’une fermeture :

I

Facilite la gestion d’état

I

Meilleurs contrôle des arrivées/départs de clients

I

Uniquement communication unicast

I

Plus lent au démarrage

Définition

En

mode non connecté

, les messages sont envoyés librement :

I

Plus facile à mettre en œuvre

(7)

Les protocoles TCP et UDP

TCP : une communication de type téléphone

I

Mode connecté : protocole de prise de connexion (lent)

I

Sans perte : un message arrive au moins un fois

I

Sans duplication : un message arrive au plus une fois

I

Avec fragmentation : les messages peuvent être coupés

I

Ordre respecté : messages délivrés dans l’ordre d’émission

UDP : une communication de type courrier

I

Mode non connecté : pas de protocole de connexion (plus rapide)

I

Avec perte : l’émetteur n’est pas assuré de la délivrance

I

Avec duplication : un message peut arriver plus d’une fois

I

Sans fragmentation : les messages envoyés ne sont jamais coupés

(8)

La notion de mode de connecté

Attention

Il ne faut pas confondre connexion au niveau transport et

connexion au niveau applicatif :

I

FTP fonctionne en connecté en utilisant TCP

I

DNS fonctionne en non-connecté en utilisant UDP

(9)

Les Sockets

Définition

Une

Socket

est une API (interface logicielle) avec les services du

système d’exploitation, qui permet d’exploiter facilement et de

manière uniforme les services d’un protocole réseau.

Une socket est un demi-point de connexion d’une application.

Machine 1

Socket

Socket

Machine 2

Java défini plusieurs classes de sockets suivant le protocole :

(10)

Outline

Une abstraction des protocoles réseau

Gestion des addresses réseau en Java

Le sockets TCP

Le sockets UDP

(11)

Identification des sockets

Une socket est identifiée par :

I

en absence de connexion : h@IP,porti

I

en cas de connexion : (h@IP

src

,port

src

i,h@IP

dest

,port

dest

i)

Attention

Deux sockets peuvent occuper le même port local si elles sont

connectées sur des IPs et/ou ports différents.

Il existe deux classes pour gérer les addresses :

(12)

InetAddress : les adresses internet

La classe

InetAddress

sert à représenter les adresses internet

I

pas de constructeur mais des méthodes statiques

InetAddress me = InetAddress.

getByName("sopena.fr");

System.

out.println(

me.

getHostAddress()+" = "+

me.

getHostName());

90.46.19.126 = sopena.fr

InetAddress g = InetAddress.

getByAddress(new

byte

[] {8,8,8,8});

System.

out.println(

g.

getHostAddress()+" = "+

g.

getCanonicalHostName());

8.8.8.8 = google-public-dns-a.google.com

InetAddress ici = InetAddress.

getLocalHost();

(13)

SocketAddress : les adresses internet

La classe

InetSocketAddress

sert à représenter h@IP,porti :

I

elle hérite de la classe abstraite

SocketAddress

I

ces instances sont des objets immuables

I

elle n’associe pas le protocole utilisé

On peut les construire ou les récupèrer de :

I

sockets existantes

I

de packets reçu ou émis

InetSocketAddress localhost =

new InetSocketAddress(

"localhost"

,

8080

);

socket.

connect

(localhost);

(14)

Outline

Une abstraction des protocoles réseau

Gestion des addresses réseau en Java

Le sockets TCP

(15)

Utilisation d’une socket TCP

Serveur

Client

y=3

x=2

(16)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

y=3

x=2

(17)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

y=3

x=2

x=-1

(18)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

y=3

x=2

x=-1

(19)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

y=3

x=2

(20)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080)

y=3

x=2

(21)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

y=3

x=2

(22)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream()

y=3

x=2

x=-1

(23)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

y=3

x=2

x=-1

(24)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

y=3

x=2

x=-1

(25)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read() os.write(2)

y=3

x=2

x=-1

(26)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x)

y=3

x=2

(27)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read()

y=3

x=2

(28)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read()

y=3

x=2

(29)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read() os = os.write(x+1) c.getOutputStream()

y=3

x=2

(30)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read() os = os.write(x+1) c.getOutputStream() print("y="+y)

y=3

x=2

(31)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read() os = os.write(x+1) c.getOutputStream() print("y="+y) x = is.read()

y=3

x=2

(32)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read() os = os.write(x+1) c.getOutputStream() print("y="+y) x = is.read()

y=3

x=2

(33)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read() os = os.write(x+1) c.getOutputStream() print("y="+y) x = is.read()

c.close()

y=3

x=2

(34)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read() os = os.write(x+1) c.getOutputStream() print("y="+y) x = is.read()

c.close() print("x="+x)

y=3

x=2

(35)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket() c.connect(localhost,8080) Socket c =

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read() os = os.write(x+1) c.getOutputStream() print("y="+y) x = is.read()

c.close() print("x="+x) c.close()

y=3

x=2

(36)

Utilisation d’une socket TCP

Serveur

Client

s = new ServerSocket(8080) s.accept()

Socket c = new Socket() c.connect(localhost,8080) Socket c =

is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream()

y = is.read() os = os.write(x+1) c.getOutputStream() print("y="+y) x = is.read() c.close() print("x="+x) c.close() s.close()

y=3

x=2

x=-1

(37)

Fermeture de la socket de connexion

Serveur

Client

s = new ServerSocket(8080) s = new ServerSocket(8080) s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

(38)

Fermeture de la socket de connexion

Serveur

Client

s = new ServerSocket(8080) s = new ServerSocket(8080) s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

(39)

Fermeture de la socket de connexion

Serveur

Client

s = new ServerSocket(8080) s = new ServerSocket(8080) s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

8080

s.close() is = c.getInputStream() os = c.getOutputStream() x = is.read()

os.write(2) print("x="+x)print("x="+x) is = c.getInputStream() y = is.read() os = c.getOutputStream() os.write(x+1) print("y="+y) x = is.read() c.close() print("x="+x) c.close()

(40)

Connexion précoce : pas de socket de connexion

Serveur

Client

Socket c = new Socket()

(41)

Connexion précoce : pas de socket de connexion

Serveur

Client

Socket c = new Socket()

(42)

Connexion précoce : pas de socket de connexion

Serveur

Client

Socket c = new Socket()

3823

c.connect(localhost,8080)

ConnectException

(43)

Connexion précoce : avant le accept du serveur

Serveur

Client

s = new ServerSocket(8080)

8080

Socket c = new Socket()

(44)

Connexion précoce : avant le accept du serveur

Serveur

Client

s = new ServerSocket(8080)

8080

Socket c = new Socket()

(45)

Connexion précoce : avant le accept du serveur

Serveur

Client

s = new ServerSocket(8080)

8080

Socket c = new Socket()

(46)

Connexion précoce : avant le accept du serveur

Serveur

Client

s = new ServerSocket(8080)

8080

s.accept()

Socket c = new Socket()

3823

c.connect(localhost,8080) Socket c =

(47)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

(48)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

(49)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

(50)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

Socket c1 =

(51)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

Socket c1 =

s.accept()

Socket c2 = new Socket(4219)

4219

(52)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

Socket c1 =

s.accept()

Socket c2 = new Socket(4219)

4219

c2.connect(localhost,8080) Socket c2 =

(53)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

Socket c1 =

s.accept()

Socket c2 = new Socket(4219)

4219

c2.connect(localhost,8080) Socket c2 =

8080

(54)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

Socket c1 =

s.accept()

Socket c2 = new Socket(4219)

4219

c2.connect(localhost,8080) Socket c2 =

8080

s.accept()

Client

Socket c = new

5829

Socket("sopena.fr",8080)

(55)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

Socket c1 =

s.accept()

Socket c2 = new Socket(4219)

4219

c2.connect(localhost,8080) Socket c2 =

8080

s.accept()

Client

Socket c = new

5829

Socket("sopena.fr",8080)

8080

Socket c3 =

(56)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

Socket c1 =

s.accept()

Socket c2 = new Socket(4219)

4219

c2.connect(localhost,8080) Socket c2 =

8080

s.accept()

Client

Socket c = new

5829

Socket("sopena.fr",8080)

8080

Socket c3 =

(57)

Connexions multiples sur une socket TCP

Serveur

s = new ServerSocket(8080)

8080

Client

8080

s.accept()

Socket c1 = new Socket()

3823

c1.connect(localhost,8080)

8080

Socket c1 =

s.accept()

Socket c2 = new Socket(4219)

4219

c2.connect(localhost,8080) Socket c2 = s.accept()

Client

Socket c = new

5829

Socket("sopena.fr",8080)

8080

Socket c3 = c2.close()

(58)

Outline

Une abstraction des protocoles réseau

Gestion des addresses réseau en Java

Le sockets TCP

(59)

Utilisation d’une socket UDP

Serveur

Client

Hell

(60)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

Hell

To port : 5782

To port : 8080

(61)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

Hell

To port : 5782

To port : 8080

(62)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

Hell

(63)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in =

new DatagramPacket(msg, 50)

@

Hell

(64)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in)

Hell

To port : 5782

To port : 8080

(65)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in)

Hell

To port : 5782

To port : 8080

(66)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

Hell

To port : 5782

To port : 8080

(67)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080)

Hell

(68)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hell

(69)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hello!

Hell

(70)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hello!

System.out.println(new String(msg))

Hello !

Hell

To port : 5782

To port : 8080

(71)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hello!

System.out.println(new String(msg)) System.out.println("From port : " + in.getPort())

Hello !

Hell

To port : 8080

(72)

Utilisation d’une socket UDP

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hello!

System.out.println(new String(msg)) System.out.println("From port : " +

in.getPort()) System.out.println("To port : " +

out.getPort())

Hello !

Hell

(73)

Émission précoce : avant ouverture de l’autre socket

Serveur

Client

Hell

(74)

Émission précoce : avant ouverture de l’autre socket

Serveur

Client

s = new DatagramSocket()

5782

Hell

To port : 5782

To port : 8080

(75)

Émission précoce : avant ouverture de l’autre socket

Serveur

Client

s = new DatagramSocket()

5782

byte msg[] = "Hello!".getBytes()

Hello!

Hell

To port : 5782

To port : 8080

(76)

Émission précoce : avant ouverture de l’autre socket

Serveur

Client

s = new DatagramSocket()

5782

byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080)

Hell

(77)

Émission précoce : avant ouverture de l’autre socket

Serveur

Client

s = new DatagramSocket()

5782

byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hell

(78)

Émission précoce : avant ouverture de l’autre socket

Serveur

Client

s = new DatagramSocket()

5782

byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out) System.out.println("To port : " + out.getPort())

Hell

To port : 5782

To port : 8080

(79)

Émission précoce : avant ouverture de l’autre socket

Serveur

Client

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out) System.out.println("To port : " + out.getPort()) s = new DatagramSocket(8080)

8080

Hell

To port : 5782

To port : 8080

(80)

Émission précoce : avant le receive du serveur

Serveur

Client

Hell

(81)

Émission précoce : avant le receive du serveur

Serveur

Client

s = new DatagramSocket()

5782

byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080)

Hell

(82)

Émission précoce : avant le receive du serveur

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080)

Hell

(83)

Émission précoce : avant le receive du serveur

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hell

(84)

Émission précoce : avant le receive du serveur

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out) System.out.println("To port : " + out.getPort())

Hell

To port : 5782

To port : 8080

(85)

Émission précoce : avant le receive du serveur

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hello!

System.out.println("To port : " + out.getPort())

Hell

To port : 5782

To port : 8080

(86)

Émission précoce : avant le receive du serveur

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hello!

System.out.println(new String(msg)) System.out.println("From port : " +

in.getPort()) System.out.println("To port : " +

out.getPort())

Hello !

Hell

(87)

Buffer de réception trop petit

Serveur

Client

Hell

(88)

Buffer de réception trop petit

Serveur

Client

s = new DatagramSocket(8080)

8080

byte msg[] = new byte[50]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in)

Hell

To port : 5782

To port : 8080

(89)

Buffer de réception trop petit

Serveur

Client

s = new DatagramSocket(8080)

8080

byte msg[] = new byte[4]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in)

Hell

To port : 5782

To port : 8080

(90)

Buffer de réception trop petit

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[4]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080)

Hell

(91)

Buffer de réception trop petit

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[4]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hell

(92)

Buffer de réception trop petit

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[4]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hell

Hell

(93)

Buffer de réception trop petit

Serveur

Client

s = new DatagramSocket(8080)

8080

s = new DatagramSocket()

5782

byte msg[] = new byte[4]

DatagramPacket in = new DatagramPacket(msg, 50) @ s.receive(in) byte msg[] = "Hello!".getBytes()

Hello!

InetAddress localhost = InetAddress.getByName("localhost") @

DatagramPacket out = new DatagramPacket( msg, 0, msg.length, localhost, 8080) s.send(out)

Hell

System.out.println(new String(msg)) System.out.println("From port : " +

in.getPort()) System.out.println("To port : " +

out.getPort())

Hell

Références

Documents relatifs

● Pour voir le résultat d'une opération, on peut demander au programme de l'afficher. ● On utilise la fonction System.out.print

● Le code source est ensuite soit traduit vers un langage compréhensible par la machine (langage binaire), on parle de compilation, soit il est interprété par un interpréteur

Il n'est pas vrai qu'en Afrique le SIDA et ses modes de transmis- sion soient différents du SIDA dans les pays industrialisés, et que l'Afrique représente un danger spécial pour

(a) Lister les variables utilisées ainsi que leur type : alphabet, mot et nouveaumot de type string (chaîne de caractères), indice de type int (entier), nouvelindice de type int?.

Modifier le programme précédent pour qu’il repère la lettre la plus fréquente, en déduire le décalage qui a pu être appliqué pour coder le message, et décoder le message?. (c)

Le présent document enregistre le type de support message/sipfrag d'extension de messagerie Internet multi objets (MIME, Multipurpose Internet Mail Extensions). Ce type est similaire

défintion d'un ensemble de fonctions et on ne peut pas définir deux ensembles de fonctions différents dans la même déclaration d'interface: d'un point de vue mathématique

 Une expression expression peut être une valeur, une variable ou une opération constituée par des valeurs, des constantes et des variables reliées entre elles par des