CRC
CRC
import java.util.Scanner;
// Take inputs
System.out.print("Enter the dataword (binary): ");
String input1 = sc.next();
System.out.print("Enter the divisor (binary): ");
String input2 = sc.next();
// Calculate CRC
String codeword = calculateCRC(input1, input2);
// Display results
System.out.println("Final Codeword: " + codeword);
}
}
SOCKET
Server.py
import socket
def start_server():
# Create a TCP/IP socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
print('Waiting for a connection...')
client_socket, client_address = server_socket.accept()
try:
print(f'Connection from {client_address}')
while True:
# Receive data from client
data = client_socket.recv(1024).decode()
print(f'Received: {data}')
elif data.startswith('Registration'):
# Process registration number
reg_num = data.replace('Registration ', '')
response = f'Registration number {reg_num} is enrolled in
VIT'
client_socket.send(response.encode())
finally:
print('Closing connection')
client_socket.close()
if __name__ == '__main__':
try:
start_server()
except KeyboardInterrupt:
print("\nServer shutting down...")
Client.py
import socket
import sys
def start_client():
# Create a TCP/IP socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Send name
name = input("Enter your message (format: My name is <your
name>): ")
client_socket.send(name.encode())
# Receive response
response = client_socket.recv(1024).decode()
print(f'Server response: {response}')
# Send registration number
reg_num = input("Enter your registration number: ")
message = f'Registration {reg_num}'
client_socket.send(message.encode())
# Receive response
response = client_socket.recv(1024).decode()
print(f'Server response: {response}')
# Send goodbye
bye_message = input("Enter 'Bye' to send to the server: ")
while bye_message.strip().lower() != 'bye':
bye_message = input("Please enter 'Bye': ")
client_socket.send(bye_message.encode())
finally:
print('Closing socket')
client_socket.close()
if __name__ == '__main__':
try:
start_client()
except KeyboardInterrupt:
print("\nClient shutting down...")