Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Network & Security Expert

When programming a server or a client, we have to deal with port numbers and IP addresses, but we usually do this through an abstraction called a socket. Sockets are the standard API for network programming; they are the abstraction which we use to describe a connection, i.e. a duplex communication. The typical way of creating and using sockets, in C, is the following:

// Client side ------------------------------------------------------------

struct addrinfo *addr;

int fd = socket(AF_INET, SOCK_STREAM, 0); // fd is the socket's filehandle
getaddrinfo("www.cnn.com", "http", NULL, &addr); // converts hostname to IP address
connect(fd, addr->ai_addr, addr->ai_addrlen); // connect to remote host
send(fd, send_buf, len, 0); // now send then receive data
...
recv(fd, recv_buf, len, 0);

// Server side ------------------------------------------------------------

struct addrinfo *addr, *remote_addr;
int fd = socket(AF_INET, SOCK_STREAM, 0);

// fd is the socket's filehandle getaddrinfo(NULL, "http", NULL, &addr); // convert service to port number ("ht bind(fd, addr->ai_addr, addr->ai_addrlen); // bind socket to a particular port nu listen(fd, 1); // listen for connections. Second argument is # of allowable waiting

// Now accept connection on socket fd; when a connection comes in, we'll move it to int newfd = accept(fd, remote_addr->ai_addr, &(remote_addr->ai_addrlen));

// we process the accepted connection on newfd, with recv() and send(),

// and at the same time, we'll keep using fd to accept other incoming connections

Computer Network & Security, Computer Science

  • Category:- Computer Network & Security
  • Reference No.:- M9528254

Have any Question?


Related Questions in Computer Network & Security

Assignment descriptionproject scope a typical

Assignment Description Project Scope: A typical network layout diagram of a firm is given below for illustrative purposes only. The service requirements are enclosed. Figure. Network layout of a firm Service requirements ...

Advanced network design assessment - human factors in

Advanced Network Design Assessment - Human factors in network analysis and design Purpose of the assessment - This assignment is designed to assess students' knowledge and skills related to the following learning outcome ...

A run in a setting is a substring of length at least two as

A run in a setting is a substring of length at least two, as long as possible, and consisting entirely of the same symbol. For instance, the string abbbaab contains a run of b's of length three and a run of a's of length ...

Assignment -global finance inc gfi - global finance inc gfi

Assignment - GLOBAL FINANCE, INC. (GFI) - Global Finance, Inc. (GFI) is a financial company that manages thousands of accounts across Canada, the United States, and Mexico. A public company traded on the NYSE, GFI specia ...

Fiona told her friend that she is very fortunate as the

Fiona told her friend that she is very fortunate as the slow-down in the economy has not decreased sales in her grocery store by much compared to sales of new cars in his car dealership. Explain what Fiona meant using th ...

Content analysis assignmentoverviewthis assignment has

Content Analysis Assignment Overview This assignment has three major aims: - To help students gain good understanding of all ITECH1102 theoretical and practical material. - To encourage students to use content analysis s ...

Question for the remaining questions consider a 4-bit block

Question : For the remaining questions, consider a 4-bit block cipher, described in hexadecimal by the following table: Plaintext Ciphertext Plaintext Ciphertext 0 a 8 e 1 c 9 d 2 f a 0 3 6 b 7 4 3 c 5 5 8 d b 6 4 e 9 7 ...

Cybersecurity policy design issues describe cybersecurity

Cybersecurity Policy Design Issues Describe cybersecurity policy features that are needed to protect against the Insider Threat, Operations Security, Access Control and Biometric Authentication What features can be added ...

Question do some research and find a case of cyber

Question : Do some research and find a case of cyber harassment or cyberbullying. Explain the case, and discuss the relevant theories of criminal justice associated with the perpetrator(s). Your response should be a mini ...

Objectivespart 1 researching network attacks- research

Objectives Part 1: Researching Network Attacks - Research network attacks that have occurred. - Select a network attack and develop a report for presentation to the class. Part 2: Researching Network Security Audit Tools ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As