Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

SISTEM TERDISTRIBUSI (SILABUS dan Introduction to Distributed Systems)

Presentasi serupa


Presentasi berjudul: "SISTEM TERDISTRIBUSI (SILABUS dan Introduction to Distributed Systems)"— Transcript presentasi:

1 SISTEM TERDISTRIBUSI (SILABUS dan Introduction to Distributed Systems)

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25 PEMROGRAMAN SOCKET PADA PHP Socket programming merupakan bahasa pemrograman yang dapat mengkomunikasikan beberapa komputer. Socket programming tidak hanya dapat berfungsi sebagai tukar menukar data melainkan juga dapat berkomunikasi dengan program lain yang berjalan pada platform non-unix melalui jaringan TCP/IP. Pada mesin unix terdapat fasilitas rlogin, ssh, ftp, dll yang menggunakan socket. Socket terdiri dari beberapa elemen utama dantaranya: 1.Protokol 2.Local IP 3.Local Port 4.Remote IP 5.Remort Port

26 Protocol Family pada socket : 1.AF_INET = IPv4 dan AF_INET6 = IPv6 adalah protocol berbasis internet termasuk TCP dan UDP 2.AF_UNIX = berfungsi sebagai komunikasi local Tipe-tipe komunikasi pada socket : 1.SOCK_STREAM 2.SOCK_SEQPACKET 3.SOCK_RAW 4.SOCK_RDM 5.SOCK_DGRAM Spesifik Protokol pada socket : TCP, UDP, ICMP Contoh script pembuatan socket : Script Socket Untuk Server mainserver.php

27

28

29

30 Send message to server <?php $host= "127.0.0.1"; $port= 9000; if($_POST['smb']){ $message = $_POST['msg']; echo "Message To server :".$message; echo ' '; $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); $result = socket_connect($socket, $host, $port) or die("Could not connect to server\n"); socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n"); $result = socket_read ($socket, 1024) or die("Could not read server response\n"); echo "Reply From Server :".$result; echo " "; socket_close($socket); } ?>

31 <? php // set some variables $host = "127.0.0.1"; $port = 9000; set _ time _ limit (0); $socket = socket _ create ( AF _ INET, SOCK _ STREAM, 0) or die (" Could not create socket \ n "); $result = socket _ bind ( $socket, $host, $port ) or die (" Could not bind to socket \ n "); $result = socket _ listen ( $socket, 3) or die (" Could not set up socket listener \ n "); while ( true ){ $spawn = socket _ accept ( $socket ) or die (" Could not accept incoming connection \ n "); $input = socket _ read ( $spawn, 1024) or die (" Could not read input \ n "); if ( $input == '! close ') { socket _ write ( $spawn, ' good bye ', strlen (' good bye ')) or die (" Could not write output \ n "); break ; } $input = trim ( $input ); $output = strrev ( $input ). "\ n "; echo " Client Message : ". $input ; echo nl 2 br ('\ n \ n '); echo " Server Reply : ". $output ; echo nl 2 br ('\ n \ n '); socket _ write ( $spawn, $output, strlen ( $output )) or die (" Could not write output \ n "); } socket _ close ( $spawn ); socket _ close ( $socket ); ?>

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82


Download ppt "SISTEM TERDISTRIBUSI (SILABUS dan Introduction to Distributed Systems)"

Presentasi serupa


Iklan oleh Google