Skip to main content

Posts

Showing posts from 2022

Computer networks lab 5 subnetting code

 def findClass(ip):     if (ip[0]>=0 and ip[0]<=126):         return "A"     elif(ip[0]>=128 and ip[0]<=191):         return "B"     elif(ip[0]>=192 and ip[0]<=223):         return "C"     elif(ip[0]>=224 and ip[0]<=239):         return "D"     else:         return "E"         def separate (ip, className):     if (className=="A"):         print("Network address is : " , ip[0])         print("Host address is : ",".".join(ip[1:4]))             elif(className=="B"):         print("Network address is : ",".".join(ip[0:2]))         print("Host address is : ",".".join(ip[2:4]))             elif(className=="C"):         print("network address is :" ,".".join(ip[1:3]))         print("Host address is :" ,ip[3])             else :         print("This ip cannot be divided in network and host

computer networks lab 6 tcp socket

 Write a program using TCP socket for wired network for following a. Say Hello to Each other b. File transfer. Server Program: /****************** SERVER CODE ****************/ #include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> int main(){ int welcomeSocket, newSocket; char buffer[1024]; struct sockaddr_in serverAddr; struct sockaddr_storage serverStorage; socklen_t addr_size; welcomeSocket = socket(PF_INET, SOCK_STREAM, 0); serverAddr.sin_family = AF_INET; serverAddr.sin_port = htons(7891); serverAddr.sin_addr.s_addr = inet_addr(“127.0.0.1”); memset(serverAddr.sin_zero, ‘\0’, sizeof serverAddr.sin_zero); bind(welcomeSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr)); if(listen(welcomeSocket,5)==0) printf(“Listening\n”); else printf(“Error\n”); addr_size = sizeof serverStorage; newSocket = accept(welcomeSocket, (struct sockaddr *) &serverStorage, &addr_size); strcpy(buff

Computer Networks lab 5 socket programming

 Socket Programming using C/C++/Java / python. a. TCP Client, TCP Server b. b. UDP Client, UDP Server. Example: UDP Server using Python import socket   localIP     = &quot;127.0.0.1&quot; localPort   = 20001 bufferSize  = 1024   msgFromServer       = &quot;Hello UDP Client&quot; bytesToSend         = str.encode(msgFromServer)   # Create a datagram socket UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)   # Bind to address and ip UDPServerSocket.bind((localIP, localPort))   print(&quot;UDP server up and listening&quot;)   # Listen for incoming datagrams while(True):     bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)     message = bytesAddressPair[0]     address = bytesAddressPair[1]     clientMsg = &quot;Message from Client:{}&quot;.format(message)     clientIP  = &quot;Client IP Address:{}&quot;.format(address)          print(clientMsg)     print(clientIP)         # Sending a reply to client     UDPServerSoc

IOT Experiment -5

   IOT Experiment -5 READ TEMPERATURE AND DISPLAY ON SERIAL MONITOR USING ARDUINO UNO IN DEGREE CELCUIS AND FAHREINHEIT SORCE CODE: const int sensor=A5; float tempc; float tempf; float vout; void setup(){   pinMode(sensor,INPUT);   Serial.begin(9600); } void loop(){   vout = analogRead(sensor);   vout=(vout *500)/1023; tempc=vout; tempf=(vout*1.8)+32; Serial.print("in DegreeC="); Serial.print("\t"); Serial.print(tempc); Serial.print("  "); Serial.print("in Fahrenheit=");   Serial.print("\t"); Serial.print(tempf); Serial.println(); delay(500); }

IOT Experiment -4

  IOT Experiment -4 READ TEMPERATURE AND DISPLAY ON SERIAL MONITOR USING ARDUINO UNO SORCE CODE: float temp; int temppin=0; void setup(){   Serial.begin(9600); } void loop(){   temp = analogRead(temppin);   temp=temp * 0.48828125;      Serial.print("temperature=");   Serial.print(temp);   Serial.print("*C");   Serial.println();   delay(1000); }

IOT Experiment -2

 IOT Experiment -2  LED INTENSITY VARIATION SORCE CODE: void Setup()  {  // initialize digital pin 5,6,7 & 8 as an output.  pinMode(5, OUTPUT);  pinMode(6, OUTPUT);  pinMode(7, OUTPUT);  digitalWrite(5, HIGH);  digitalWrite(6, HIGH);  digitalWrite(7, HIGH);  }   void Loop()  {  digitalWrite(5, HIGH);  digitalWrite(6, LOW);  digitalWrite(7, LOW);  delay(500); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, HIGH); delay(500); digitalWrite(5, LOW); digitalWrite(6, HIGH); digitalWrite(7, LOW); delay(500); int red_light_pin= 7; int green_light_pin = 6; int blue_light_pin = 5; int count = 0; void setup() {   pinMode(red_light_pin, OUTPUT);   pinMode(green_light_pin, OUTPUT);   pinMode(blue_light_pin, OUTPUT); } void loop() {   if (count >= 0 && count<=100)   {   RGB_color(255, 0, 255); // Yellow   delay(50);   count++;   }   else if (count >= 101 && count<=200)   {   RGB_color(0, 0, 255); // Green   delay(50);   count++;   }   else   {   RGB_color(