![]() |
|
Tutorial networking - 2 - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Computers (https://sinister.li/Forum-Computers) +--- Forum: Networking (https://sinister.li/Forum-Networking) +--- Thread: Tutorial networking - 2 (/Thread-Tutorial-networking-2) |
networking - 2 - MrSecurity - 01-12-2018 networking 2 today i'll be talking about Subnet mask wild card (tcp client UDP client tcp server coded with python-,) network sockets A network socket is an internal endpoint for sending or receiving data at a single node in a computer network. network address contains an IP (internet protocol) address and port number. In a very simple way, a socket is a way to talk to other computers. By means of a socket, a process can communicate with another process over the network. In order to create a socket, use the socket.socket() function that is available in the socket module. The general syntax of a socket function is as follows: s = socket.socket (socket_family, socket_type, protocol=0) Here is the description of the parameters: socket_family: socket.AF_INET, PF_PACKET AF_INET is the address family for IPv4. PF_PACKET operates at the device driver layer. The pcap library for Linux uses PF_PACKET. These arguments represent the address families and the protocol of the transport layer Socket_type : socket.SOCK_DGRAM, socket.SOCK_RAW,socket.SOCK_STREAM The socket.SOCK_DGRAM argument depicts that UDP is unreliable and connectionless, and socket.SOCK_STREAM depicts that TCP is reliable and is a two-way, connection-based service. Server socket In a client-server architecture, there is one centralized server that provides service, and many clients request and receive service from the centralized server. Here are some methods you need to know: socket.bind(address): This method is used to connect the address (IP address, port number) to the socket. The socket must be open before connecting to the address. socket.listen(q): This method starts the TCP listener. The q argument defines the maximum number of lined-up connections. socket.accept(): The use of this method is to accept the connection from the client. Before using this method, the socket.bind(address) and socket.listen(q) methods must be used. The socket.accept() method returns two values: client_socket and address, where client_socket is a new socket object used to send and receive data over the connection, and address is the address of the client. client socket The only method dedicated to the client is the following: socket.connect(address): This method connects the client to the server. Socket methods
The server is in the listening mode, and the client connects to the server. The following diagram shows how the client accepts a connection from the server ![]() UDP client server connection ![]() ![]() TCP client Code: import socket
host = "192.168.0.1" # server address
port =12345 #server port
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((host,port))
print rep.recv(1024)
client.send("Hello Server")
client.close()Code: import socket
host = "192.168.0.1" #Server address
port = 12345 #Port of Server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port)) #bind server
s.listen(2)
conn, addr = s.accept()
print addr, "Connected"
conn.send("Connection established!")
conn.close()UDP client Code: import socket
target_host = "address"
target_port = port
# create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# send some data
client.sendto("AAABBBCCC",(target_host,target_port))
#receive some data
data, addr = client.recvfrom(4096)
print datasubnet addressing IP networks can be divided into smaller networks called subnetworks (or subnets). Subnetting provides the network administrator with several benefits, including extra flexibility, more efficient use of network addresses, and the capability to contain broadcast traffic (a broadcast will not cross a router.Subnets are under local administration. As such, the outside world sees an organization as a single network and has no detailed knowledge of the organization’s internal structure. A given network address can be broken up into many subnetworks. For example, 172.16.1.0, 172.16.2.0, 172.16.3.0, and 172.16.4.0 are all subnets within network 172.16.0.0. (All 0s in the host portion of an address specifies the entire network, subnet mask A subnet address is created by using bits from the host field and designating them as the subnet field. The number of borrowed bits varies and is specified by the subnet mask questions suggestions? comment below RE: networking - 2 - darkcracker - 03-25-2018 Execellent tut! 1 RE: networking - 2 - mothered - 03-26-2018 It's nice to read you've defined a short, yet effective, post on subnets. I still come across many users who don't understand the basics. |