forked from averagesecurityguy/Python-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
34 lines (27 loc) · 1.21 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
#-----------------------------------------------------------------------------
# This example will open a client connection to localhost on the specified
# port. Data is sent to the server and then recv'd from the server. The data
# received is written to standard out.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Import any needed libraries below
#-----------------------------------------------------------------------------
# We need to use the socket library
import socket
#-----------------------------------------------------------------------------
# Begin the main program.
#-----------------------------------------------------------------------------
# Create a new socket and specify the host and port to connect to
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = '127.0.0.1'
port = 80
# Connect to the host and port
sock.connect((host, port))
# Send data to the server.
send = "Sending some data..."
print "Sending -> %s" % (send)
sock.send(send)
# Receive data from the server and print it to standard out.
data = sock.recv(1024)
print "Received -> %s" % (data)