Skip to main content

Computer network 6 SOCKET PROGRAMMING






Socket Programming using UDP Socket.

 

The user datagram protocol (UDP) works differently from TCP/IP. Where TCP is a stream oriented protocol, ensuring that all of the data is transmitted in the right order, UDP is a message oriented protocol. UDP does not require a long-lived connection, so setting up a UDP socket is a little simpler. On the other hand, UDP messages must fit within a single packet (for IPv4, that means they can only hold 65,507 bytes because the 65,535 byte packet also includes header information) and delivery is not guaranteed as it is with TCP.
Server
import socket
import sys
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = (‘localhost’, 10000)
print >>sys.stderr, ‘starting up on %s port %s’ % server_address
sock.bind(server_address)
while True:
    print >>sys.stderr, ‘\nwaiting to receive message’
    data, address = sock.recvfrom(4096)
    print >>sys.stderr, ‘received %s bytes from %s’ % (len(data),
address)
    print >>sys.stderr, data
    if data:
        sent = sock.sendto(data, address)
        print >>sys.stderr, ‘sent %s bytes back to %s’ % (sent, address)
Client 
import socket
import sys
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = (‘localhost’, 10000)
message = ‘This is the message.  It will be repeated.’
try:
   print >>sys.stderr, ‘sending “%s”‘ % message
    sent = sock.sendto(message, server_address)
   print >>sys.stderr, ‘waiting to receive’
    data, server = sock.recvfrom(4096)
    print >>sys.stderr, ‘received “%s”‘ % data
finally:
    print >>sys.stderr, ‘closing socket’
    sock.close()

 

Comments

Popular posts from this blog

Packet Tracer Simulation – TCP and UDP Communications Part 1: Generate Network Traffic in Simulation Mode Step 1: Generate traffic to populate Address Resolution Protocol (ARP) tables.  Click MultiServer and click the Desktop tab > Command Prompt.  Enter the ping 192.168.1.255 command. This will take a few seconds as every device on the network responds to MultiServer.  Close the MultiServer window. Step 2: Generate web (HTTP) traffic.  Switch to Simulation mode.  Click HTTP Client and click the Desktop tab > Web Browser.  In the URL field, enter 192.168.1.254 and click Go. Envelopes (PDUs) will appear in the simulation window.  Minimize, but do not close, the HTTP Client configuration window. Step 3: Generate FTP traffic.  Click FTP Client and click the Desktop tab > Command Prompt.  Enter the ftp 192.168.1.254 command. PDUs will appear in the simulation window.  Minim...
Configuration of Static/Dynamic NAT in Cisco Router Static NAT (Network Address Translation) is one-to-one mapping of a private IP address to a public IP address. Static NAT (Network Address Translation) is useful when a network device inside a private network needs to be accessible from internet. In order to configure NAT we have to understand four basic terms; inside local, inside global, outside local and outside global. These terms define which address will be mapped with which address. Term : Description Inside Local IP Address : Before translation source IP address located inside the local network. Inside Global IP Address : After translation source IP address located outside the local network. Outside Global IP Address: Before translation destination IP address located outside the remote network. Outside Local IP Address : After translation destination IP address locat...

About Cisco packet tracer

About Cisco packet tracer Packet Tracer is a cross-platform visual simulation tool designed by Cisco Systems that allows users to create network topologies and imitate modern computer networks. The software allows users to simulate the configuration of Cisco routers and switches using a simulated command line interface. Packet Tracer makes use of a drag and drop user interface, allowing users to add and remove simulated network devices as they see fit. Key Features   Packet Tracer Works-paces: Cisco Packet Tracer has two work- spaces—logical and physical. The logical workspace allows users to build logical network topologies by placing, connecting, and clustering virtual network devices. The physical workspace pro vides a graphical physical dimension of the logical network, giving a sense of scale and placement in how network devices such as routers, switches, and hosts would look in a real environment. The physical view also provides geographic representations of...