Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { AttackService } from './attack.service';
- import { WebSocketService } from '../../../lib/service/websocket/websocket.service';
- import { WebSocketConfig } from '../../../lib/service/websocket/websocket.config';
- @Component({
- selector: 'attack',
- templateUrl: './attack.component.html',
- styleUrls: ['./attack.component.css'],
- providers: [AttackService, WebSocketService]
- })
- export class AttackComponent implements OnInit {
- private model: Object = {
- url: "http://localhost",
- kb_per_request: 5,
- duration: 5
- };
- private hasReceivedMessage: boolean = false;
- private totalRequests: number = 0;
- private payloadSize: number = 0;
- private payloadSizeType: string = 'KB';
- constructor(private attackService: AttackService, private socket: WebSocketService) {}
- ngOnInit(): void {
- this.socket.create(new WebSocketConfig(this.sOnOpen, this.sOnClose, this.sOnMessage, this.sOnError));
- }
- sOnOpen(): void {
- console.log('WebSocket connection successfully established.');
- }
- sOnClose(code: number): void {
- console.log(`WebSocket connection closed (${code}).`);
- }
- sOnMessage(data: any): void {
- this.hasReceivedMessage = true;
- this.totalRequests = data.total_requests;
- this.payloadSize = data.payload_size;
- this.payloadSizeType = data.payload_size_type;
- console.log('====================================');
- console.log('Total requests: ', this.totalRequests);
- console.log('Payload size: ', this.payloadSize);
- console.log('Payload type: ', this.payloadSizeType);
- }
- sOnError(data: any): void {
- console.log('WebSocket error occurred: ', data);
- }
- submit(): void {
- this.attackService.attack(this.model).subscribe(
- res => {
- let data = res.json();
- if (data.success) {
- console.log(data.message);
- }
- },
- err => {
- console.log('Error:', err);
- }
- );
- }
- }
- constructor(private attackService: AttackService, private socket: WebSocketService) {
- this.sOnOpen = this.sOnOpen.bind(this);
- this.sOnClose = this.sOnClose.bind(this);
- this.sOnMessage = this.sOnMessage.bind(this);
- this.sOnError = this.sOnError.bind(this);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement