Difference between revisions of "Python: Echo Server"

From OnnoWiki
Jump to navigation Jump to search
(New page: Here is a simple echo server (echoserver-simple.py): #!/usr/bin/env python """ A simple echo server """ import socket host = '' port = 50000 backlog = 5 size = 1024 s = s...)
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Here is a simple echo server (echoserver-simple.py):
+
==Simple Echo Server==
 +
 
 +
Sebuah simple echo server (echoserver-simple.py):
  
 
  #!/usr/bin/env python
 
  #!/usr/bin/env python
 
"""
 
A simple echo server
 
"""
 
 
   
 
   
 
  import socket  
 
  import socket  
Line 24: Line 22:
  
  
A Simple Echo Client
+
==Sebuah Echo Client Sederhana==
  
Here is an echo client that will talk to our echo server (echoclient-simple.py):
+
Simple echo client (echoclient-simple.py):
  
 
  #!/usr/bin/env python
 
  #!/usr/bin/env python
+
 
"""
 
A simple echo client
 
"""
 
 
 
  import socket  
 
  import socket  
 
   
 
   
Line 47: Line 41:
  
  
 +
 +
==Alternatif Test menggunakan nc==
 +
 +
nc ipserver 5000
 +
 +
Ketikan
 +
 +
tulisan / kata2 yang ingin anda kirim
  
 
==Referensi==
 
==Referensi==
  
 
* http://ilab.cs.byu.edu/python/socket/echoserver.html
 
* http://ilab.cs.byu.edu/python/socket/echoserver.html

Latest revision as of 10:17, 4 December 2015

Simple Echo Server

Sebuah simple echo server (echoserver-simple.py):

#!/usr/bin/env python

import socket 

host = 
port = 50000
backlog = 5
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)
while 1:
    client, address = s.accept()
    data = client.recv(size)
    if data:
        client.send(data)
    client.close() 


Sebuah Echo Client Sederhana

Simple echo client (echoclient-simple.py):

#!/usr/bin/env python
 
import socket 

host = 'localhost'
port = 50000
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
s.send('Hello, world')
data = s.recv(size)
s.close()
print 'Received:', data  


Alternatif Test menggunakan nc

nc ipserver 5000

Ketikan

tulisan / kata2 yang ingin anda kirim

Referensi