Friday, May 22, 2020

The Issue Of Mineral Rights Essay - 1954 Words

As a first-time homebuyer in the Dallas/Fort Worth area, I thought I had very carefully prepared myself for all that the process would involve, including gathering income and financial documentation, qualifying for a mortgage, arranging for a thorough inspection, evaluating needs and desires from a home and finding a reputable agent to represent my interests. One area I never considered, however, was the issue of mineral rights. To be perfectly honest, although I d heard the term, I d never given consideration to what it actually meant. But that all changed in the middle of my home buying process - and I d like to share with you the knowledge I ve gained through extensive research I completed to protect my own rights and the rights I would possess as a soon-to-be homeowner. According to property law, two different forms of rights exist in any real property: surface rights and mineral rights. Surface rights refer to any structure erected above the surface or sub-surface structures th at do not exceed a certain depth, as well as rights to use all surface property surrounding structures in accordance with zoning ordinances. Mineral rights refer to mineral substances below a certain depth and the way in which they are preserved, explored or extracted. These mineral substances can include natural gas, oil, or any other substance in common use today that can be mined or otherwise extracted from below the surface. Local laws set the depth below which surface rights terminateShow MoreRelatedThe Mining Act 1990830 Words   |  4 Pages1990, has a significant role in protecting Ontario’s vast mineral resources and brings forth a set of policies in which promote responsible mining development and extraction. The provincial government plays an integral role in the provinces mining industry because the Act requires that all mineral claims must be recorded and accepted by the Crown which from then the two parties discuss a lease fee for the mineral rights. After loca ting a mineral claim in an area deemed open by the Crown, there are twoRead MoreCadia Case Analysis Essay1726 Words   |  7 PagesHoldings Pty Ltd and Newcrest Operations Ltd (NOL) owned land in New South Wales, granted to them by the State of New South Wales under the Mining Act 1992 (NSW). From July 1998 to March 2008, Cadia conducted mining operations in which it recovered minerals including copper and gold, and paid royalties to the Minister pursuant to the Mining Act 1992 (NSW). The Minister referred to the Case of Mines[1], claiming that the mine owned by Cadia was a â€Å"royal mine† containing gold that belonged to the CrownRead MoreBare Minerals vs Pur Minerals851 Words   |  4 PagesBare Minerals versus Pur Minerals Kristina McClary English 112 March 4, 2010 In the last ten years the cosmetics has transcends from chemical base to natural from foundations and blushes to lip color and eye makeup. Women have many choices in cosmetics brands, such as department specialty discount stores brands. Due to the growing popularity of natural cosmetics in demand specialty cosmetic companies like Bare Minerals and Pur minerals were introduce to answer. Bare Minerals the first toRead MoreMandated Disclosure Of Conflict Minerals : Does It Work?1626 Words   |  7 PagesSection 1502 Mandated Disclosure of Conflict Minerals: Does it work? In short form, Section 1502 of the Dodd-Frank Wall Street Reform and Consumer Protection Act mandates disclosure of conflict minerals originated in the Democratic Republic of the Congo (DRC) to the Securities Exchange Commission (SEC) and due diligence in sourcing those conflict minerals. Conflict minerals include gold, tantalum, tin, and tungsten, which are used in many popular consumer products used and manufactured throughoutRead MoreThe Law Of General Application1414 Words   |  6 PagesMINISTER FOR MINERALS AND ENERGY 2013 (4) SA 1 (CC) The facts of the case were that â€Å"Sebenza (Pty) Ltd bought coal rights from the liquidators of Kwa-Zulu Collieries (Pty) Ltd for R1 048 800 on 2 October 2001 and registered them in its name. S was not the owner of the land on which the coal was located. [14] On 1 May 2004 the MPRDA came into effect. S became the holder of an unused old order right on that date. This happened in terms of item 8 of schedule II to the MPRDA. Unused old order rights were inRead MoreA Brief Note On Mining And Its Impact On The Environment Essay1376 Words   |  6 Pagesespecially in Canada.Canada has one of the largest mining supply sectors in the world,more than 3 700 companies and is one of the largest mineral suppliers.Canada is first place for Potash,second place for uranium and niobium,third place for cobalt,aluminum,tungsten and platinum group metals (M.A.C,n.d.).Mining is important because it is the process of discovering the minerals that are used to make steel,,jewelry,lead,and many other types of metals used everyday.Mining may be useful but it has a negativeRead MoreThe Oil And Natural Gas1240 Words   |  5 Pagesa piece of land does not mean he or she has the right to set up a lease for the drilling of oil or gas. Before mining and drilling was possible the ownership of land was simple, the owner owned the surface, subsurface and the air above the surface. Today it is possible for an owner to only own the surface of their land, this is called surface rights. In order to set up a drilling lease the owner must posses the surface rights and the mining rights which means that they own wants beneath the surfaceRead MoreThe Mining Of Conflict Minerals1427 Words   |  6 Pages Conflict minerals are used in many commercially available items, such as many electronic devices and much jewelry. These minerals are Tin, Tantalum, Tungsten and Gold. Mines, in which these minerals are collected, are often sites for violent armed groups, hence the name conflict minerals. This problem is especially prominent in the Democratic Republic of Congo, but also takes place in many other nations such as the Central African Republic, Tanzania and Angola as well. These nations often do notRead MoreEthics And The Ethical Dilemma1252 Words   |  6 Pagesthey mostly depends on manufacturers in Asia. But the manufacturers never knew where the minerals they use come from. The Apple company used conflict minerals which is against human rights and they extracted illegally from Congo mineral deposits. It is a great mistake done by them. This reflected the ethics of Integrity and Leadership .Two things that reflect these ethics are that using of conflict minerals and the second is not to reveal this to the manufacturers. Apple started facing pressureRead MoreOur Nutrition And Food We Eat1251 Words   |  6 Pagesconditions (Axelson, Federline and Brinberg). Around a large portion of the wellbeing heap of food is attributable to dangerous water, unaltered sanitation and cleanliness. Interestingly, in industrialized countries, over-food and food wellbeing issues, including food borne disorders impacting human wellbeing furthermore impacts joined with cultivating creation schemas, are pervasive concerns. There is furthermore a foremost rate of under food among destitute, and a higher inconvenience of both

Saturday, May 9, 2020

Events that Lead to the Civil War Essay - 1754 Words

Events that Lead to the Civil War The civil war is known for its issues of slavery and the conflict between the north and the south. The split in the union can be traced as far back as the 1810’s, just as the industrial revolution was beginning. With the industrial revolution’s effects on the north and the south caused the economy to split. The north became more industrialized; the south started relaying more on agriculture. In the north, machines, interchangeable parts, and mass production took over, and started the building of factories. These first factories were used for making textiles and later evolved to manufacturing a wide variety of goods. This sparked opportunity for jobs, and with immigrants flooding in form Europe it†¦show more content†¦In 1828, A Tariff was passed to help try to protect New England Manufactures. The tariff was as high as 45% to 50% of the original European price. The north wanted these higher tariffs so their products could compete on the same level as the cheaper foreign products. Opponents of the tariff called it the Tariff of Abomination. Southerners were opposed to the tariff because they exported cotton and other materials to Europe in exchange European goods were imported to America. Southerners claimed it was an indirect tax on their region of the United States. Southerner s began to ask for states rights. South Carolina even went as far as to ask for the tariff taken off or they would succeed. The tariff was lowered by Congress. The north didn’t need to buy as many foreign products as the south because they were very self-reliant. After the United States went to war with Mexico, a win meant more land but, the Missouri Compromise of 1820, only dealt with the Louisiana Territory. In 1846, David Wilmot, of Pennsylvania, proposed an answer. His plan said: any land acquired from Mexico was to be free land. The House passed the bill, but it was shot down in the Senate. It was able to pass in the House because Northerners controlled it but it was unable to pass in the Senate because Southerners controlled it. This was a big issue because it showed that there was little that either side could do to pass a law that oneShow MoreRelatedPre-Civil War: Events that Lead to the Abolition of the Slave Trade and Slavery768 Words   |  4 Pagesslavery. Prosser and a group of his followers would procure armor and weapons then try and take over the city, thus freeing them from slavery. Unfortunately before they could execute the plan, him and some of his followers were put to death, an event that would prove to be a catalyst to the uprising. Following their deaths and many more to come, Africans slaves then would attempt to flee from their plantation or masters and run for freedom. Slaves in the southern states flee to the North justRead MoreTaking a Look at the American Civil War896 Words   |  4 PagesMany events during the mid-1700-1800s provoked the civil war because of the contradicting ideas between the northern states and the southern states. The conflict between the north and south that led to the civil war includes economic, social, and political events. At the meantime, slavery arose as a huge debate between the pro-slavery and anti-slavery faction. Fierce debates had sparked between the north and south states because of the southern states’ agrarian based economy. The geography in theRead MoreThe Legacy Of The Vietnam War967 Words   |  4 Pagesdistinction of being a year in which civil unrest, social progress, and the state of change were the norm, and featured events that affec ted not only America, but the world as a whole. With the condition of America at the time, society was going through changes that would go on to have massive impact on how the world would progress, with some of these events having effects years afterwards. The Vietnam War had been going on for nine years up to this point, and the events that would occur during 1968 wouldRead MoreThe Rights of Women in the Unites States from 1846 to the Civil War789 Words   |  4 PagesThere were wars and many political changes that lead to better opportunities in society for women and slaves. Many things happened between 1846 and the civil war in the early 1850’s woman started to revolt and realize there was more to life then just being human puppets. Then shortly after that the parties started to separate and states began to fear that the president would take away their slaves so in fear of that they started to separate from the united states. The last events lead to an unwantedRead MoreKatherine Ramjit. Mr. Staccone. T2 History. April 28Th,1194 Words   |  5 PagesStaccone T2 History April 28th, 2017 Through What Events Was Slavery The Main Cause Of the American Civil War of 1861-1865 Some may argue that the main causes of the Civil War was The Missouri Compromise, the Kansas-Nebraska Act, the Compromise of 1850 and or much more. There is a multitude of reasons or causes that people can argue about what really started the War. One important factor to take in account is that most events leading up towards the Civil War really revolved to slavery. Slavery can be definedRead MoreNorth South Tensions Before Civil War868 Words   |  4 PagesAjit Beeki Ms. Jones North-South Tensions before Civil War The Civil War was not a spontaneous conflict, rather it was the culmination of various events in American history that were in the two decades preceding it. These events exposed a rift in American society which would eventually lead to the Civil War. Among these events were the Kansas-Nebraska Act and Mexican-American War. Both of them lead to a highly polarized reactions from Northerners and Southerners in the slavery debate. In the endRead MoreThe American Revolution1190 Words   |  5 Pagesdescendants of participants in the war and created a focus on the importance of ancestry, leads the belief that there were another motivating factor behind an organization of this type. Influencing the founders of the D.A.R. was both the Civil War and the rising immigration to the United States. The Civil War ended with slaves becoming freemen and citizens, affecting the definition of citizenship. Also the war increase patriotic drive in the citizens which directly lead the forming of th e patrioticRead Morecivil war963 Words   |  4 Pages Prompt: There were numerous events and crises during the 1850’s that contributed to the advent of the civil war. Choose three and analyze the relative significance of each in contributing to the advent of the Civil War. During the time period of the mid 1800’s there was a great deal of growing tension between the northern and southern states. Many northerners were abolitionists and were anti slavery, the northerners didn’t want to outlaw slavery completely but wanted to put an end to slaveryRead MoreCause Of The Civil War On America1290 Words   |  6 Pages1301 Professor Harris December 3, 2015 Causes of the Civil War Lasting from 1861-1865 The Civil war: one of the most bloodiest and alienated wars in the American History has had a tremendous impact on our past society, and modern as well. In the early 1800’s the United States accomplished harmony, alliance, and unification, eventually causing sectionalism to flourish. This controversy led to the famous bloody war, known as the Civil war. While the south wanted to separate, and become one, theRead MoreWhat Events Sparked The Civil War?779 Words   |  4 Pages Mrs. McGee English 2 27 April 2015 What Events Sparked the Civil War? â€Å"We here highly resolve that these dead shall not have died in vain.† Abraham Lincoln spoke this during the time the Civil War had ended. There were several major events that helped spark the Civil War; Uncle Tom’s Cabin, John Brown’s Raid, Lincoln’s Election, and the Battle at Fort Sumter. The Civil war was one of the hardest fought battles in American history. In 1852, Uncle Tom’s Cabin

Wednesday, May 6, 2020

The Secret Circle The Divide Chapter 8 Free Essays

The kitchen was shadowy and quiet when Cassie stepped inside. Her mother wasn’t home, and she was glad. She didn’t want to have to explain why she was hauling bricks out of the fireplace. We will write a custom essay sample on The Secret Circle: The Divide Chapter 8 or any similar topic only for you Order Now Just up the block, Diana was retrieving the tiara and whatever other materials they’d need to complete the resuscitation spell. And a little farther down Crowhaven Road, the rest of the group was somehow going to convince Melanie to allow them to bring her great-aunt’s body to the lighthouse. Before this year, Cassie had never even seen a real dead body, and now she was going to put her hands over one and try to bring it back to life. The fireplace wasn’t such a creative hiding spot for the bracelet, Cassie knew, but it had worked successfully for so many years, why try to think up someplace different? Deep inside its gaping stone mouth, she found the silver document box just as she’d left it. And when she removed its ancient lid, the bracelet glistened inside, as if it were celebrating the sudden, surprising light. Cassie allowed herself to admire the bracelet’s beauty for only a second. She ran her fingers over the intricate design on its rich silver surface and felt its weight in her hands. But then Diana called to her from outside. â€Å"Be right there!† she yelled, and ran upstairs to quickly change into her ceremonial white shift. Once she was dressed and ready, she found Diana waiting for her on the front porch swing with a large cotton sack at her side. She’d also changed into her ceremonial shift, but there was a composure to Diana’s appearance that Cassie could only aspire to. Even under all this stress, Diana remained in control. Cassie reached for her hand, hoping some of the strength would rub off Diana’s skin onto hers. And somehow it did. A few moments of holding Diana close calmed her. â€Å"We’re doing the right thing,† Diana said. â€Å"We need Constance.† Cassie remembered what a refuge Constance had been since she lost her grandmother. And all the afternoons she’d spent in her parlor, learning new spells and studying ancient rituals. Constance was the only connection to the old ways the Circle had. â€Å"I know we are,† Cassie said in her most courageous voice. â€Å"I’m ready to go.† â€Å"Okay, everyone, let’s get started.† Diana emptied the cotton sack onto the table when they arrived at the lighthouse and immediately began reading directions from her Book of Shadows. It didn’t surprise Cassie how everyone automatically turned to Diana in moments like this – moments when it really mattered. She would always be the most natural leader among them, no matter what. â€Å"The body should be entirely covered in white cloth of two layers,† Diana read aloud to Adam. â€Å"With head and face veiled in tull e.† She gestured to a pile of fine white netting on the table. Adam nodded. â€Å"I’ll take care of it,† he said. Nick, Chris, and Doug pushed all the furniture to the room’s perimeter. Melanie kneeled in the center beside the covered body. Cassie helped Deborah drape the windows with purple linens. Diana approached Faye carrying two golden censers. â€Å"We have to fumigate the chamber with sage and frankincense,† she said. Faye had changed into her ceremonial black shift, and she was already wearing the green leather garter with its seven silver buckles. She accepted the censers from Diana and then called Sean over to tend to the chore. â€Å"Where’s the diadem?† she asked. Diana nodded over to Melanie, sitting solemnly with the diadem on her head. â€Å"She’s the one who gets to wear the Tools tonight,† Diana said. â€Å"She’s doing the conjuring. The rest of us are her support.† Even Faye couldn’t disagree that Melanie should be the one leading this spell, but she still tore the garter from her leg with fury before walking it over to Melanie. Cassie followed close behind her, removing the bracelet from her wrist on her way. In a few minutes, the room had been properly prepared, and Diana called for the ritual to begin. â€Å"Faye and Cassie, will you do the honors of casting the circle according to my instructions? Forgive me if I go slowly – this text is really hard to read – but I’ll do my best. Is everyone ready?† Cassie looked around the dimly lit room. She wasn’t the only one who seemed nervous, but nobody was about to back out now. Melanie appeared to be in a cloudy-eyed daze, but she looked more beautiful wearing the Master Tools than Cassie had ever seen her. Diana cleared her throat and began reading aloud. â€Å"A magic circle is to be formed upon the ground with an ink of soot and port wine. A second circle is formed half a foot within the first.† Together Cassie and Faye formed the circles around Melanie and Constance, using the chalice of ink Diana had prepared. â€Å"And within there,† Diana continued, â€Å"cast a triangle, the center of which will serve as the resting place of the deceased and primary conjurer.† Cassie and Faye formed the triangle within the circles, outlining Melanie and Constance. â€Å"Everyone get inside,† Diana said. â€Å"And then I’ll close the outer circle with the four layers of protection.† Quickly the group arranged itself, kneeling upon the outer circle’s perimeter as Diana called on the elements. â€Å"Powers of Air, protect us,† Diana called out. â€Å"Powers of Fire, protect us.† Cassie closed her eyes and listened. â€Å"Powers of Water, protect us.† Diana enunciated each syllable with precision. â€Å"And finally,† she said, â€Å"I call on the powers of Earth to protect us.† Diana then joined the circle beside Cassie and continued reading from her Book of Shadows. â€Å"To commence, the conjurer must light a black candle and cast it over the body seven times thereon, calling the name of the spirit to be raised.† All eyes turned to Melanie now. Cassie wondered if she had the strength to do it. But the Tools glistened, and Melanie’s posture straightened as she lit the candle and passed it over the white sheet, calling out, â€Å"Great-Aunt Constance, Constance Burke, hear us.† Diana continued, â€Å"Then from a golden chalice of dried amaranth flowers, sprinkle the body and its surrounding area.† While Melanie did the sprinkling, Diana said, â€Å"Melanie, repeat after me: Thou who art mourned, see now the nature of this mourning.† And Melanie repeated, â€Å"Thou who art mourned, see now the nature of this mourning.† Cassie felt her eyes fill with tears as Diana chanted: This is the spell that we intone Flesh to flesh and bone to bone Sinew to sinew and vein to vein Constance shall be whole again They all concentrated hard, harnessing their powers together as one. Cassie could sense an energy rising up from the center triangle, webbing out to each member of the group, linking them all together in a maze of light. Diana read aloud, â€Å"After a moment of silence and concentration, uncover the face of the deceased. Then call to the spirit again, affectionately. Say ‘Welcome.'† With quivering hands, Melanie gently unveiled Constance’s face. â€Å"Great-Aunt Constance,† she said. â€Å"Welcome.† â€Å"The body will stir,† Diana read. â€Å"The eyes will open, and then the desired awakening.† The room crackled with energy. Cassie could feel it zipping and twisting around her in spirals, but she wasn’t afraid of it anymore. The air around them warmed, and Cassie could see the life flickering back into Constance’s face slowly, like the rising sun. Then a shape began to form. Cassie noticed it faintly at first in the glow on Constance’s forehead, but then it grew bigger and brighter until it stood out like an iridescent bruise. It was most definitely a symbol, a primal-looking mark resembling two crooked U-shapes within a hexagon. Then everything went dark. The light that had come to Constance’s face, the symbol, the candles ill uminating the room – all of it disappeared, as if a heavy blanket were dropped from the ceiling, snuffing the room to death. Diana lit her lantern and held it up to Melanie’s grief-stricken face. Her great-aunt Constance was still dead. And now she had to experience her death all over again. â€Å"The spell didn’t work,† Laurel said. â€Å"But it was working.† Diana’s eyes franticly searched the group. â€Å"Didn’t you all feel it?† â€Å"Yes, of course,† Adam said. â€Å"I don’t understand what went wrong.† Faye was silent but looked just as confused as the others. Adam spoke out again. â€Å"Is there anything more to the spell, Diana? Does it say anything else in your book?† Diana squinted at the bottom of the page she’d been reading, then turned to the next page, and then turned it back again. â€Å"It’s nearly ill egible,† she said. â€Å"But there’s a scrawled line here at the bottom edge.† She held her lantern close to the book’s tiny wording. â€Å"It says, ‘Should nothing result, and this witch hath been true . . .’ and then it stops. Whatever it said next got smudged out.† â€Å"Smudged out?† Faye grabbed the book from Diana’s hands to have a look for herself. â€Å"How could something so important be smudged out?† â€Å"It’s a three-hundred-year-old book,† Adam said in Diana’s defense. â€Å"It’s not that hard to believe.† Cassie wondered if she was the only one who saw the symbol appear on Constance’s forehead. Or had she imagined it? Over the echoes of Melanie’s sobs, she knew it wasn’t the right time to ask. Constance was lost to them forever. It was late by the time Cassie got back home, but her mother was awake, lying on the sofa in her nightgown. She sat upright as soon as Cassie stepped in from outside. â€Å"Are you all right?† she asked. â€Å"Yes,† Cassie assured her, closing and locking the door behind her. â€Å"How’s Melanie?† â€Å"She’s been better.† Cassie pulled her jacket tightly closed, not wanting her mother to see she was wearing the white shift. â€Å"And Constance?† Cassie hesitated. She realized her mother was eyeing the Master bracelet on Cassie’s left wrist. â€Å"You know then,† Cassie said. â€Å"About the resuscitation spell.† Her mom nodded and gestured for Cassie to join her on the sofa. â€Å"I just figured,† she said. â€Å"Did it work?† At first Cassie simply shook her head and took off her coat. But she wanted to be able to tell her mom everything, even about the symbol she saw ill uminating Constance’s forehead. And for once she did, without holding anything back for her mother’s benefit. Her mother surprised her by listening, really listening this time. She didn’t change the subject or become so overwhelmed with fear that Cassie had to worry about her more than herself. Until she mentioned the symbol she saw appear on Constance’s forehead. â€Å"The symbol,† Cassie said, â€Å"looked like something primal. Like two bent U-shapes inside a hexagon.† Cassie noticed the alarmed look that flashed across her mother’s face. â€Å"What is it?† Her mother shook her head. â€Å"Not two U-shapes,† she said. â€Å"One. A W.† Cassie didn’t understand what she was hearing. â€Å"W, as in Witch,† her mother said. Cassie was breathless. Her mother closed her eyes for a moment and when she reopened them they looked as grim as two black coals. â€Å"I know what went wrong with the spell,† she said. â€Å"There’s a way a witch can be killed that can never be reversed. But there’s only one kind of person who can do it.† â€Å"Who?† Cassie asked. â€Å"What kind of person?† â€Å"A witch hunter,† her mother said. How to cite The Secret Circle: The Divide Chapter 8, Essay examples

Tuesday, April 28, 2020

Network Programming with Sockets Essay Example

Network Programming with Sockets Essay Socket programming got you down? Is this stuff just a little too difficult to figure out from the man pages? You want to do cool Internet programming, but you dont have time to wade through a gob of structs trying to figure out if you have to call bind() before you connect(), etc. , etc. Well, guess what! Ive already done this nasty business, and Im dying to share the information with everyone! Youve come to the right place.This document should give the average competent C programmer the edge s/he needs to get a grip on this networking noise. Audience This document has been written as a tutorial, not a reference. It is probably at its best when read by individuals who are just starting out with socket programming and are looking for a foothold. It is certainly not the complete guide to sockets programming, by any means. Hopefully, though, itll be just enough for those man pages to start making sense 🙂 Platform and Compiler Most of the code contained within this document was compiled on a Linux PC using Gnus gcc compiler.It was also found to compile on HPUX using gcc. Note that every code snippet was not individually tested. Contents: What is a socket? Two Types of Internet Sockets Low level Nonsense and Network Theory structsKnow these, or aliens will destroy the planet! Convert the Natives! IP Addresses and How to Deal With Them socket()Get the File Descriptor! bind()What port am I on? connect()Hey, you! listen()Will somebody please call me? 1 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html accept()Thank you for calling port 3490. end() and recv()Talk to me, baby! sendto() and recvfrom()Talk to me, DGRAM-style close() and shutdown()Get outta my face! getpeername()Who are you? gethostname()Who am I? DNSYou say whitehouse. gov, I say 198. 137. 240. 100 Client-Server Background A Simple Stream Server A Simple Stream Client Datagram Sockets Blocking select()Synch ronous I/O Multiplexing. Cool! More references Disclaimer and Call for Help What is a socket? You hear talk of sockets all the time, and perhaps you are wondering just what they are exactly. Well, theyre this: a way to speak to other programs using standard Unix file descriptors.What? Okyou may have heard some Unix hacker state, Jeez, everything in Unix is a file! What that person may have been talking about is the fact that when Unix programs do any sort of I/O, they do it by reading or writing to a file descriptor. A file descriptor is simply an integer associated with an open file. But (and heres the catch), that file can be a network connection, a FIFO, a pipe, a terminal, a real on-the-disk file, or just about anything else. Everything in Unix is a file! So when you want to communicate with another program over the Internet youre gonna do it through a file descriptor, youd better believe it. Where do I get this file descriptor for network communication, Mr. Smarty-Pants? is p robably the last question on your mind right now, but Im going to answer it anyway: You make a call to the socket() system routine. It returns the socket descriptor, and you communicate through it using the specialized send() and recv() (man send, man recv) socket calls. But, hey! you might be exclaiming right about now. If its a file descriptor, why in the hell cant I just use the normal read() and write() calls to communicate through the socket? The short answer is, You can! The longer answer is, You can, but send() and recv() offer much greater control over your data transmission. What next? How about this: there are all kinds of sockets. There are DARPA Internet addresses (Internet Sockets), path names on a local node (Unix Sockets), CCITT X. 25 addresses (X. 25 Sockets that you can safely ignore), and probably many others depending on which Unix flavor you run. This document deals only with the first: Internet Sockets. Two Types of Internet Sockets 2 of 26 12. 03. 99 01:21 B eejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. tml Whats this? There are two types of Internet sockets? Yes. Well, no. Im lying. There are more, but I didnt want to scare you. Im only going to talk about two types here. Except for this sentence, where Im going to tell you that Raw Sockets are also very powerful and you should look them up. All right, already. What are the two types? One is Stream Sockets; the other is Datagram Sockets, which may hereafter be referred to as SOCK_STREAM and SOCK_DGRAM, respectively. Datagram sockets are sometimes called connectionless sockets (though they can be connect()d if you really want.See connect(), below. Stream sockets are reliable two-way connected communication streams. If you output two items into the socket in the order 1, 2, they will arrive in the order 1, 2 at the opposite end. They will also be error free. Any errors you do encounter are figments of your own deranged min d, and are not to be discussed here. What uses stream sockets? Well, you may have heard of the telnet application, yes? It uses stream sockets. All the characters you type need to arrive in the same order you type them, right? Also, WWW browsers use the HTTP protocol which uses stream sockets to get pages.Indeed, if you telnet to a WWW site on port 80, and type GET pagename, itll dump the HTML back at you! How do stream sockets achieve this high level of data transmission quality? They use a protocol called The Transmission Control Protocol, otherwise known as TCP (see RFC-793 for extremely detailed info on TCP. ) TCP makes sure your data arrives sequentially and error-free. You may have heard TCP before as the better half of TCP/IP where IP stands for Internet Protocol (see RFC-791. ) IP deals with Internet routing only. Cool. What about Datagram sockets? Why are they called connectionless?What is the deal, here, anyway? Why are they unreliable? Well, here are some facts: if you se nd a datagram, it may arrive. It may arrive out of order. If it arrives, the data within the packet will be error-free. Datagram sockets also use IP for routing, but they dont use TCP; they use the User Datagram Protocol, or UDP (see RFC-768. ) Why are they connectionless? Well, basically, its because you dont have to maintain an open connection as you do with stream sockets. You just build a packet, slap an IP header on it with destination information, and send it out. No connection needed.They are generally used for packet-by-packet transfers of information. Sample applications: tftp, bootp, etc. Enough! you may scream. How do these programs even work if datagrams might get lost?! Well, my human friend, each has its own protocol on top of UDP. For example, the tftp protocol says that for each packet that gets sent, the recipient has to send back a packet that says, I got it! (an ACK packet. ) If the sender of the original packet gets no reply in, say, five seconds, hell re-tran smit the packet until he finally gets an ACK. This acknowledgment procedure is very important when implementing SOCK_DGRAM applications.Low level Nonsense and Network Theory Since I just mentioned layering of protocols, its time to talk about how networks really work, and to show some examples of how SOCK_DGRAM packets are built. Practically, you can probably skip this section. Its good background, however. 3 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html Hey, kids, its time to learn about Data Encapsulation! This is very very important. Its so important that you might just learn about it if you take the networks course here at Chico State ;-).Basically, it says this: a packet is born, the packet is wrapped (encapsulated) in a header (and maybe footer) by the first protocol (say, the TFTP protocol), then the whole thing (TFTP header included) is encapsulated again by the next protocol (say, UDP), then again by the next (IP), then again by the final protocol on the hardware (physical) layer (say, Ethernet). When another computer receives the packet, the hardware strips the Ethernet header, the kernel strips the IP and UDP headers, the TFTP program strips the TFTP header, and it finally has the data. Now I can finally talk about the infamous Layered Network Model.This Network Model describes a system of network functionality that has many advantages over other models. For instance, you can write sockets programs that are exactly the same without caring how the data is physically transmitted (serial, thin Ethernet, AUI, whatever) because programs on lower levels deal with it for you. The actual network hardware and topology is transparent to the socket programmer. Without any further ado, Ill present the layers of the full-blown model. Remember this for network class exams: Application Presentation Session Transport Network Data Link Physical The Physical Layer is the ha rdware (serial, Ethernet, etc. . The Application Layer is just about as far from the physical layer as you can imagineits the place where users interact with the network. Now, this model is so general you could probably use it as an automobile repair guide if you really wanted to. A layered model more consistent with Unix might be: Application Layer (telnet, ftp, etc. ) Host-to-Host Transport Layer (TCP, UDP) Internet Layer (IP and routing) Network Access Layer (was Network, Data Link, and Physical) At this point in time, you can probably see how these layers correspond to the encapsulation of the original data.See how much work there is in building a simple packet? Jeez! And you have to type in the packet headers yourself using cat! Just kidding. All you have to do for stream sockets is send() the data out. All you have to do for datagram sockets is encapsulate the packet in the method of your choosing and sendto() it out. The kernel builds the Transport Layer and Internet Layer on for you and the hardware does the Network Access Layer. Ah, modern technology. So ends our brief foray into network theory. Oh yes, I forgot to tell you everything I wanted to say about routing: nothing! Thats right, Im not going to talk about it at all.The router strips the packet to the IP header, consults its routing table, blah blah blah. Check out the IP RFC if you really really care. If you never learn about it, well, youll live. [Encapsulated Protocols Image] 4 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html structs Well, were finally here. Its time to talk about programming. In this section, Ill cover various data types used by the sockets interface, since some of them are a real bitch to figure out. First the easy one: a socket descriptor.A socket descriptor is the following type: int Just a regular int. Things get weird from here, so just read through and bear with me. Know this: there are two byte orderings: most significant byte (sometimes called an octet) first, or least significant byte first. The former is called Network Byte Order. Some machines store their numbers internally in Network Byte Order, some dont. When I say something has to be in NBO, you have to call a function (such as htons()) to change it from Host Byte Order. If I dont say NBO, then you must leave the value in Host Byte Order. My First Struct(TM)struct sockaddr.This structure holds socket address information for many types of sockets: struct sockaddr { unsigned short sa_family; /* address family, AF_xxx */ char sa_data[14]; /* 14 bytes of protocol address */ }; sa_family can be a variety of things, but itll be AF_INET for everything we do in this document. sa_data contains a destination address and port number for the socket. This is rather unwieldy. To deal with struct sockaddr, programmers created a parallel structure: struct sockaddr_in (in for Internet. ) struct sockaddr_in { shor t int sin_family; /* Address family */ unsigned short int sin_port; /* Port number */ truct in_addr sin_addr; /* Internet address */ unsigned char sin_zero[8]; /* Same size as struct sockaddr */ }; This structure makes it easy to reference elements of the socket address. Note that sin_zero (which is included to pad the structure to the length of a struct sockaddr) should be set to all zeros with the function bzero() or memset(). Also, and this is the important bit, a pointer to a struct sockaddr_in can be cast to a pointer to a struct sockaddr and vice-versa. So even though socket() wants a struct sockaddr *, you can still use a struct sockaddr_in and cast it at the last minute!Also, notice that sin_family corresponds to sa_family in a struct sockaddr and should be set to AF_INET. Finally, the sin_port and sin_addr must be in Network Byte Order! But, you object, how can the entire structure, struct in_addr sin_addr, be in Network Byte Order? This question requires careful examinati on of the structure struct in_addr, one of the worst unions alive: /* Internet address (a structure for historical reasons) */ 5 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html struct in_addr { nsigned long s_addr; }; Well, it used to be a union, but now those days seem to be gone. Good riddance. So if you have declared ina to be of type struct sockaddr_in, then ina. sin_addr. s_addr references the 4 byte IP address (in Network Byte Order). Note that even if your system still uses the God-awful union for struct in_addr, you can still reference the 4 byte IP address in exactly the same way as I did above (this due to #defines. ) Convert the Natives! Weve now been lead right into the next section. Theres been too much talk about this Network to Host Byte Order conversionnow is the time for action!All righty. There are two types that you can convert: short (two bytes) and long (four bytes). The se functions work for the unsigned variations as well. Say you want to convert a short from Host Byte Order to Network Byte Order. Start with h for host, follow it with to, then n for network, and s for short: h-to-n-s, or htons() (read: Host to Network Short). Its almost too easy You can use every combination if n, h, s, and l you want, not counting the really stupid ones. For example, there is NOT a stolh() (Short to Long Host) functionnot at this party, anyway.But there are: htons()Host to Network Short htonl()Host to Network Long ntohs()Network to Host Short ntohl()Network to Host Long Now, you may think youre wising up to this. You might think, What do I do if I have to change byte order on a char? Then you might think, Uh, never mind. You might also think that since your 68000 machine already uses network byte order, you dont have to call htonl() on your IP addresses. You would be right, BUT if you try to port to a machine that has reverse network byte order, your program wi ll fail. Be portable! This is a Unix world!Remember: put your bytes in Network Order before you put them on the network. A final point: why do sin_addr and sin_port need to be in Network Byte Order in a struct sockaddr_in, but sin_family does not? The answer: sin_addr and sin_port get encapsulated in the packet at the IP and UDP layers, respectively. Thus, they must be in Network Byte Order. However, the sin_family field is only used by the kernel to determine what type of address the structure contains, so it must be in Host Byte Order. Also, since sin_family does not get sent out on the network, it can be in Host Byte Order.IP Addresses and How to Deal With Them Fortunately for you, there are a bunch of functions that allow you to manipulate IP addresses. No need to figure them out by hand and stuff them in a long with the h_addr); bzero(;(their_addr. sin_zero), 8); /* zero the rest of the struct */ if ((numbytes=sendto(sockfd, argv[2], strlen(argv[2]), 0, (struct sockaddr *);thei r_addr, sizeof(struct sockaddr))) == -1) { perror(sendto); exit(1); } printf(sent %d bytes to %s ,numbytes,inet_ntoa(their_addr. sin_addr)); close(sockfd); return 0; } And thats all there is to it!Run listener on some machine, then run talker on another. Watch them communicate! Fun G-rated excitement for the entire nuclear family! Except for one more tiny detail that Ive mentioned many times in the past: connected datagram sockets. I need to talk about this here, since were in the datagram section of the document. Lets say that talker calls connect() and specifies the listeners address. From that point on, talker may only sent to and receive from the address specified by connect(). For this reason, you dont have to use sendto() and recvfrom(); you can simply use send() and recv().Blocking Blocking. Youve heard about itnow what the hell is it? In a nutshell, block is techie jargon for sleep. You probably noticed that when you run listener, above, it just sits there until a packet arrives. What happened is that it called recvfrom(), there was no data, and so recvfrom() is said to block (that is, sleep there) until some data arrives. Lots of functions block. accept() blocks. All the recv*() functions block. The reason they can do this is because theyre allowed to. When you first create the socket descriptor with socket(), the kernel sets it to blocking.If you dont want a socket to be blocking, you have to make a call to fcntl(): #include #include . . sockfd = socket(AF_INET, SOCK_STREAM, 0); fcntl(sockfd, F_SETFL, O_NONBLOCK); . . By setting a socket to non-blocking, you can effectively poll the socket for information. If you try to read from a non-blocking socket and theres no data there, its not allowed to blockit will return -1 and errno will be set to EWOULDBLOCK. Generally speaking, however, this type of polling is a bad idea. If you put your program in a busy-wait looking for data on the socket, youll suck up CPU time like it was going out of style.A more elegant solution for checking to see if theres data waiting to be read comes in the following secti on on 21 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html select(). select()Synchronous I/O Multiplexing This function is somewhat strange, but its very useful. Take the following situation: you are a server and you want to listen for incoming connections as well as keep reading from the connections you already have. No problem, you say, just an accept() and a couple of recv()s. Not so fast, buster!What if youre blocking on an accept() call? How are you going to recv() data at the same time? Use non-blocking sockets! No way! You dont want to be a CPU hog. What, then? select() gives you the power to monitor several sockets at the same time. Itll tell you which ones are ready for reading, which are ready for writing, and which sockets have raised exceptions, if you really want to know that. Without any further ado, Ill offer the synopsis of select(): #include #include #include int select(int n umfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);The function monitors sets of file descriptors; in particular readfds, writefds, and exceptfds. If you want to see if you can read from standard input and some socket descriptor, sockfd, just add the file descriptors 0 and sockfd to the set readfds. The parameter numfds should be set to the values of the highest file descriptor plus one. In this example, it should be set to sockfd+1, since it is assuredly higher than standard input (0). When select() returns, readfds will be modified to reflect which of the file descriptors you selected is ready for reading. You can test them with the macro FD_ISSET(), below.Before progressing much further, Ill talk about how to manipulate these sets. Each set is of the type fd_set. The following macros operate on this type: FD_ZERO(fd_set *set) clears a file descriptor set FD_SET(int fd, fd_set *set) adds fd to the set FD_CLR(int fd, fd_set *set) removes fd fro m the set FD_ISSET(int fd, fd_set *set) tests to see if fd is in the set Finally, what is this weirded out struct timeval? Well, sometimes you dont want to wait forever for someone to send you some data. Maybe every 96 seconds you want to print Still Going to the terminal even though nothing has happened.This time structure allows you to specify a timeout period. If the time is exceeded and select() still hasnt found any ready file descriptors, itll return so you can continue processing. The struct timeval has the follow fields: struct timeval { int tv_sec; /* seconds */ int tv_usec; /* microseconds */ }; 22 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html Just set tv_sec to the number of seconds to wait, and set tv_usec to the number of microseconds to wait. Yes, thats microseconds, not milliseconds.There are 1,000 microseconds in a millisecond, and 1,000 milliseconds in a second. Thus, th ere are 1,000,000 microseconds in a second. Why is it usec? The u is supposed to look like the Greek letter Mu that we use for micro. Also, when the function returns, timeout might be updated to show the time still remaining. This depends on what flavor of Unix youre running. Yay! We have a microsecond resolution timer! Well, dont count on it. Standard Unix timeslice is 100 milliseconds, so youll probably have to wait at least that long, no matter how small you set your struct timeval.Other things of interest: If you set the fields in your struct timeval to 0, select() will timeout immediately, effectively polling all the file descriptors in your sets. If you set the parameter timeout to NULL, it will never timeout, and will wait until the first file descriptor is ready. Finally, if you dont care about waiting for a certain set, you can just set it to NULL in the call to select(). The following code snippet waits 2. 5 seconds for something to appear on standard input: #include #incl ude #include #define STDIN 0 /* file descriptor for standard input */ main() { struct timeval tv; fd_set readfds; tv. v_sec = 2; tv. tv_usec = 500000; FD_ZERO(;readfds); FD_SET(STDIN, ;readfds); /* dont care about writefds and exceptfds: */ select(STDIN+1, ;readfds, NULL, NULL, ;tv); if (FD_ISSET(STDIN, ;readfds)) printf(A key was pressed! ); else printf(Timed out. ); } If youre on a line buffered terminal, the key you hit should be RETURN or it will time out anyway. Now, some of you might think this is a great way to wait for data on a datagram socketand you are right: it might be. Some Unices can use select in this manner, and some cant. You should see what your local man page says on the matter if you want to attempt it.One final note of interest about select(): if you have a socket that is listen()ing, you can check to see if there is a new connection by putting that sockets file descriptor in the readfds set. And that, my friends, is a quick overview of the almighty select() function. More References 23 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html Youve come this far, and now youre screaming for more! Where else can you go to learn more about all this stuff? Try the following man pages, for starters: ocket() bind() connect() listen() accept() se nd() recv() sendto() recvfrom() close() shutdown() getpeername() getsockname() gethostbyname() gethostbyaddr() getprotobyname() fcntl() select() perror() Also, look up the following books: Internetworking with TCP/IP, volumes I-III by Douglas E. Comer and David L. Stevens. Published by Prentice Hall. Second edition ISBNs: 0-13-468505-9, 0-13-472242-6, 0-13-474222-2. There is a third edition of this set which covers IPv6 and IP over ATM. Using C on the UNIX System by David A. Curry. Published by OReilly ; Associates, Inc. ISBN 0-937175-23-4.TCP/IP Network Administration by Craig Hunt. Published by OReilly Associates, Inc. ISBN 0-937175-82-X. TCP/IP Illustrated, volumes 1-3 by W. Richard Stevens and Gary R. Wright. Published by Addison Wesley. ISBNs: 0-201-63346-9, 0-201-63354-X, 0-201-63495-3. Unix Network Programming by W. Richard Stevens. Published by Prentice Hall. ISBN 0-13-949876-1. On the web: BSD Sockets: A Quick And Dirty Primer (http://www. cs. umn. edu/~bentlema/unix/has o ther great Unix system programming info, too! ) Client-Server Computing (http://pandonia. canberra. edu. au/ClientServer/socket. html)Intro to TCP/IP (gopher) 24 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html (gopher://gopher-chem. ucdavis. edu/11/Index/Internet_aw/Intro_the_Internet/intro. to. ip/) Internet Protocol Frequently Asked Questions (France) (http://web. cnam. fr/Network/TCP-IP/) The Unix Socket FAQ (http://www. ibrado. com/sock-faq/) RFCsthe real dirt: RFC-768 The User Datagram Protocol (UDP) (ftp://nic. ddn. mil/rfc/rfc768. txt) RFC-791 The Internet Protocol (IP) (ftp://nic. ddn. mil/rfc/rfc791. txt)RFC-793 The Transmission Control Protocol (TCP) (ftp://nic. ddn. mil/rfc/rfc793. txt) RFC-854 The Telnet Protocol (ftp://nic. ddn. mil/rfc/rfc854. txt) RFC-951 The Bootstrap Protocol (BOOTP) (ftp://nic. ddn. mil/rfc/rfc951. txt) RFC-1350 The Trivial File Transfer Protocol (TFT P) (ftp://nic. ddn. mil/rfc/rfc1350. txt) Disclaimer and Call for Help Well, thats the lot of it. Hopefully at least some of the information contained within this document has been remotely accurate and I sincerely hope there arent any glaring errors. Well, sure, there always are. So, if there are, thats tough for you.Im sorry if any inaccuracies contained herein have caused you any grief, but you just cant hold me accountable. See, I dont stand behind a single word of this document, legally speaking. This is my warning to you: the whole thing could be a load of crap. But its probably not. After all, Ive spent many many hours messing with this stuff, and implemented several TCP/IP network utilities for Windows (including Telnet) as summer work. Im not the sockets god; Im just some guy. By the way, if anyone has any constructive (or destructive) criticism about this document, please send mail to [emailprotected] csuchico. du and Ill try to make an effort to set the record straight. I n case youre wondering why I did this, well, I did it for the money. Hah! No, really, I did it because a lot of people have asked me socket-related questions and when I tell them Ive been thinking about putting together a socket page, they say, cool! Besides, I feel that all this hard-earned knowledge is going to waste if I cant share it with others. WWW just happens to 25 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html be the perfect vehicle.I encourage others to provide similar information whenever possible. Enough of thisback to coding! 😉 Copyright  © 1995, 1996 by Brian Beej Hall. This guide may be reprinted in any medium provided that its content is not altered, it is presented in its entirety, and this copyright notice remains intact. Contact [emailprotected] csuchico. edu for more information. 26 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Da teien/Manualz/not ad ramming; Using Internet Sockets/net. htmlBeejs Guide to Network Programming Using Internet Sockets Version 1. 5. 4 (17-May-1998) [http://www. cst. csuchico. edu/~beej/guide/net] Intro Hey! Socket programming got you down? Is this stuff just a little too difficult to figure out from the man pages? You want to do cool Internet programming, but you dont have time to wade through a gob of structs trying to figure out if you have to call bind() before you connect(), etc. , etc. Well, guess what! Ive already done this nasty business, and Im dying to share the information with everyone! Youve come to the right place. This document should give the average competent C programmer the edge s/he needs to get a grip on this networking noise. AudienceThis document has been written as a tutorial, not a reference. It is probably at its best when read by individuals who are just starting out with socket programming and are looking for a foothold. It is certainly not the complete guide to sockets programming, by any means. Hopefully, though, itll be just enough for those man pages to start making sense 🙂 Platform and Compiler Most of the code contained within this document was compiled on a Linux PC using Gnus gcc compiler. It was also found to compile on HPUX using gcc. Note that every code snippet was not individually tested. Contents: What is a socket?Two Types of Internet Sockets Low level Nonsense and Network Theory structsKnow these, or aliens will destroy the planet! Convert the Natives! IP Addresses and How to Deal With Them socket()Get the File Descriptor! bind()What port am I on? connect()Hey, you! listen()Will somebody please call me? 1 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html accept()Thank you for calling port 3490. send() and recv()Talk to me, baby! sendto() and recvfrom()Talk to me, DGRAM-style close() and shutdown()Get outta my face! etpeername()Who are you? gethostname()Who am I? DNSYou say whitehouse. gov, I say 198. 137. 240. 100 Client-Server Background A Simple Stream Server A Simple Stream Client Datagram Sockets Blocking select()Synchronous I/O Multiplexing. Cool! More references Disclaimer and Call for Help What is a socket? You hear talk of sockets all the time, and perhaps you are wondering just what they are exactly. Well, theyre this: a way to speak to other programs using standard Unix file descriptors. What? Okyou may have heard some Unix hacker state, Jeez, everything in Unix is a file! What that person may have been talking about is the fact that when Unix programs do any sort of I/O, they do it by reading or writing to a file descriptor. A file descriptor is simply an integer associated with an open file. But (and heres the catch), that file can be a network connection, a FIFO, a pipe, a terminal, a real on-the-disk file, or just about anything else. Everything in Unix is a file! So when you wan t to communicate with another program over the Internet youre gonna do it through a file descriptor, youd better believe it. Where do I get this file descriptor for network communication, Mr.Smarty-Pants? is probably the last question on your mind right now, but Im going to answer it anyway: You make a call to the socket() system routine. It returns the socket descriptor, and you communicate through it using the specialized send() and recv() (man send, man recv) socket calls. But, hey! you might be exclaiming right about now. If its a file descriptor, why in the hell cant I just use the normal read() and write() calls to communicate through the socket? The short answer is, You can! The longer answer is, You can, but send() and recv() offer much greater control over your data transmission. What next? How about this: there are all kinds of sockets. There are DARPA Internet addresses (Internet Sockets), path names on a local node (Unix Sockets), CCITT X. 25 addresses (X. 25 Sockets that you can safely ignore), and probably many others depending on which Unix flavor you run. This document deals only with the first: Internet Sockets. Two Types of Internet Sockets 2 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html Whats this? There are two types of Internet sockets? Yes. Well, no. Im lying.There are more, but I didnt want to scare you. Im only going to talk about two types here. Except for this sentence, where Im going to tell you that Raw Sockets are also very powerful and you should look them up. All right, already. What are the two types? One is Stream Sockets; the other is Datagram Sockets, which may hereafter be referred to as SOCK_STREAM and SOCK_DGRAM, respectively. Datagram sockets are sometimes called connectionless sockets (though they can be connect()d if you really want. See connect(), below. Stream sockets Network Programming with Sockets Essay Example Network Programming with Sockets Essay Socket programming got you down? Is this stuff just a little too difficult to figure out from the man pages? You want to do cool Internet programming, but you dont have time to wade through a gob of structs trying to figure out if you have to call bind() before you connect(), etc. , etc. Well, guess what! Ive already done this nasty business, and Im dying to share the information with everyone! Youve come to the right place.This document should give the average competent C programmer the edge s/he needs to get a grip on this networking noise. Audience This document has been written as a tutorial, not a reference. It is probably at its best when read by individuals who are just starting out with socket programming and are looking for a foothold. It is certainly not the complete guide to sockets programming, by any means. Hopefully, though, itll be just enough for those man pages to start making sense 🙂 Platform and Compiler Most of the code contained within this document was compiled on a Linux PC using Gnus gcc compiler.It was also found to compile on HPUX using gcc. Note that every code snippet was not individually tested. Contents: What is a socket? Two Types of Internet Sockets Low level Nonsense and Network Theory structsKnow these, or aliens will destroy the planet! Convert the Natives! IP Addresses and How to Deal With Them socket()Get the File Descriptor! bind()What port am I on? connect()Hey, you! listen()Will somebody please call me? 1 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html accept()Thank you for calling port 3490. end() and recv()Talk to me, baby! sendto() and recvfrom()Talk to me, DGRAM-style close() and shutdown()Get outta my face! getpeername()Who are you? gethostname()Who am I? DNSYou say whitehouse. gov, I say 198. 137. 240. 100 Client-Server Background A Simple Stream Server A Simple Stream Client Datagram Sockets Blocking select()Synch ronous I/O Multiplexing. Cool! More references Disclaimer and Call for Help What is a socket? You hear talk of sockets all the time, and perhaps you are wondering just what they are exactly. Well, theyre this: a way to speak to other programs using standard Unix file descriptors.What? Okyou may have heard some Unix hacker state, Jeez, everything in Unix is a file! What that person may have been talking about is the fact that when Unix programs do any sort of I/O, they do it by reading or writing to a file descriptor. A file descriptor is simply an integer associated with an open file. But (and heres the catch), that file can be a network connection, a FIFO, a pipe, a terminal, a real on-the-disk file, or just about anything else. Everything in Unix is a file! So when you want to communicate with another program over the Internet youre gonna do it through a file descriptor, youd better believe it. Where do I get this file descriptor for network communication, Mr. Smarty-Pants? is p robably the last question on your mind right now, but Im going to answer it anyway: You make a call to the socket() system routine. It returns the socket descriptor, and you communicate through it using the specialized send() and recv() (man send, man recv) socket calls. But, hey! you might be exclaiming right about now. If its a file descriptor, why in the hell cant I just use the normal read() and write() calls to communicate through the socket? The short answer is, You can! The longer answer is, You can, but send() and recv() offer much greater control over your data transmission. What next? How about this: there are all kinds of sockets. There are DARPA Internet addresses (Internet Sockets), path names on a local node (Unix Sockets), CCITT X. 25 addresses (X. 25 Sockets that you can safely ignore), and probably many others depending on which Unix flavor you run. This document deals only with the first: Internet Sockets. Two Types of Internet Sockets 2 of 26 12. 03. 99 01:21 B eejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. tml Whats this? There are two types of Internet sockets? Yes. Well, no. Im lying. There are more, but I didnt want to scare you. Im only going to talk about two types here. Except for this sentence, where Im going to tell you that Raw Sockets are also very powerful and you should look them up. All right, already. What are the two types? One is Stream Sockets; the other is Datagram Sockets, which may hereafter be referred to as SOCK_STREAM and SOCK_DGRAM, respectively. Datagram sockets are sometimes called connectionless sockets (though they can be connect()d if you really want.See connect(), below. Stream sockets are reliable two-way connected communication streams. If you output two items into the socket in the order 1, 2, they will arrive in the order 1, 2 at the opposite end. They will also be error free. Any errors you do encounter are figments of your own deranged min d, and are not to be discussed here. What uses stream sockets? Well, you may have heard of the telnet application, yes? It uses stream sockets. All the characters you type need to arrive in the same order you type them, right? Also, WWW browsers use the HTTP protocol which uses stream sockets to get pages.Indeed, if you telnet to a WWW site on port 80, and type GET pagename, itll dump the HTML back at you! How do stream sockets achieve this high level of data transmission quality? They use a protocol called The Transmission Control Protocol, otherwise known as TCP (see RFC-793 for extremely detailed info on TCP. ) TCP makes sure your data arrives sequentially and error-free. You may have heard TCP before as the better half of TCP/IP where IP stands for Internet Protocol (see RFC-791. ) IP deals with Internet routing only. Cool. What about Datagram sockets? Why are they called connectionless?What is the deal, here, anyway? Why are they unreliable? Well, here are some facts: if you se nd a datagram, it may arrive. It may arrive out of order. If it arrives, the data within the packet will be error-free. Datagram sockets also use IP for routing, but they dont use TCP; they use the User Datagram Protocol, or UDP (see RFC-768. ) Why are they connectionless? Well, basically, its because you dont have to maintain an open connection as you do with stream sockets. You just build a packet, slap an IP header on it with destination information, and send it out. No connection needed.They are generally used for packet-by-packet transfers of information. Sample applications: tftp, bootp, etc. Enough! you may scream. How do these programs even work if datagrams might get lost?! Well, my human friend, each has its own protocol on top of UDP. For example, the tftp protocol says that for each packet that gets sent, the recipient has to send back a packet that says, I got it! (an ACK packet. ) If the sender of the original packet gets no reply in, say, five seconds, hell re-tran smit the packet until he finally gets an ACK. This acknowledgment procedure is very important when implementing SOCK_DGRAM applications.Low level Nonsense and Network Theory Since I just mentioned layering of protocols, its time to talk about how networks really work, and to show some examples of how SOCK_DGRAM packets are built. Practically, you can probably skip this section. Its good background, however. 3 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html Hey, kids, its time to learn about Data Encapsulation! This is very very important. Its so important that you might just learn about it if you take the networks course here at Chico State ;-).Basically, it says this: a packet is born, the packet is wrapped (encapsulated) in a header (and maybe footer) by the first protocol (say, the TFTP protocol), then the whole thing (TFTP header included) is encapsulated again by the next protocol (say, UDP), then again by the next (IP), then again by the final protocol on the hardware (physical) layer (say, Ethernet). When another computer receives the packet, the hardware strips the Ethernet header, the kernel strips the IP and UDP headers, the TFTP program strips the TFTP header, and it finally has the data. Now I can finally talk about the infamous Layered Network Model.This Network Model describes a system of network functionality that has many advantages over other models. For instance, you can write sockets programs that are exactly the same without caring how the data is physically transmitted (serial, thin Ethernet, AUI, whatever) because programs on lower levels deal with it for you. The actual network hardware and topology is transparent to the socket programmer. Without any further ado, Ill present the layers of the full-blown model. Remember this for network class exams: Application Presentation Session Transport Network Data Link Physical The Physical Layer is the ha rdware (serial, Ethernet, etc. . The Application Layer is just about as far from the physical layer as you can imagineits the place where users interact with the network. Now, this model is so general you could probably use it as an automobile repair guide if you really wanted to. A layered model more consistent with Unix might be: Application Layer (telnet, ftp, etc. ) Host-to-Host Transport Layer (TCP, UDP) Internet Layer (IP and routing) Network Access Layer (was Network, Data Link, and Physical) At this point in time, you can probably see how these layers correspond to the encapsulation of the original data.See how much work there is in building a simple packet? Jeez! And you have to type in the packet headers yourself using cat! Just kidding. All you have to do for stream sockets is send() the data out. All you have to do for datagram sockets is encapsulate the packet in the method of your choosing and sendto() it out. The kernel builds the Transport Layer and Internet Layer on for you and the hardware does the Network Access Layer. Ah, modern technology. So ends our brief foray into network theory. Oh yes, I forgot to tell you everything I wanted to say about routing: nothing! Thats right, Im not going to talk about it at all.The router strips the packet to the IP header, consults its routing table, blah blah blah. Check out the IP RFC if you really really care. If you never learn about it, well, youll live. [Encapsulated Protocols Image] 4 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html structs Well, were finally here. Its time to talk about programming. In this section, Ill cover various data types used by the sockets interface, since some of them are a real bitch to figure out. First the easy one: a socket descriptor.A socket descriptor is the following type: int Just a regular int. Things get weird from here, so just read through and bear with me. Know this: there are two byte orderings: most significant byte (sometimes called an octet) first, or least significant byte first. The former is called Network Byte Order. Some machines store their numbers internally in Network Byte Order, some dont. When I say something has to be in NBO, you have to call a function (such as htons()) to change it from Host Byte Order. If I dont say NBO, then you must leave the value in Host Byte Order. My First Struct(TM)struct sockaddr.This structure holds socket address information for many types of sockets: struct sockaddr { unsigned short sa_family; /* address family, AF_xxx */ char sa_data[14]; /* 14 bytes of protocol address */ }; sa_family can be a variety of things, but itll be AF_INET for everything we do in this document. sa_data contains a destination address and port number for the socket. This is rather unwieldy. To deal with struct sockaddr, programmers created a parallel structure: struct sockaddr_in (in for Internet. ) struct sockaddr_in { shor t int sin_family; /* Address family */ unsigned short int sin_port; /* Port number */ truct in_addr sin_addr; /* Internet address */ unsigned char sin_zero[8]; /* Same size as struct sockaddr */ }; This structure makes it easy to reference elements of the socket address. Note that sin_zero (which is included to pad the structure to the length of a struct sockaddr) should be set to all zeros with the function bzero() or memset(). Also, and this is the important bit, a pointer to a struct sockaddr_in can be cast to a pointer to a struct sockaddr and vice-versa. So even though socket() wants a struct sockaddr *, you can still use a struct sockaddr_in and cast it at the last minute!Also, notice that sin_family corresponds to sa_family in a struct sockaddr and should be set to AF_INET. Finally, the sin_port and sin_addr must be in Network Byte Order! But, you object, how can the entire structure, struct in_addr sin_addr, be in Network Byte Order? This question requires careful examinati on of the structure struct in_addr, one of the worst unions alive: /* Internet address (a structure for historical reasons) */ 5 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html struct in_addr { nsigned long s_addr; }; Well, it used to be a union, but now those days seem to be gone. Good riddance. So if you have declared ina to be of type struct sockaddr_in, then ina. sin_addr. s_addr references the 4 byte IP address (in Network Byte Order). Note that even if your system still uses the God-awful union for struct in_addr, you can still reference the 4 byte IP address in exactly the same way as I did above (this due to #defines. ) Convert the Natives! Weve now been lead right into the next section. Theres been too much talk about this Network to Host Byte Order conversionnow is the time for action!All righty. There are two types that you can convert: short (two bytes) and long (four bytes). The se functions work for the unsigned variations as well. Say you want to convert a short from Host Byte Order to Network Byte Order. Start with h for host, follow it with to, then n for network, and s for short: h-to-n-s, or htons() (read: Host to Network Short). Its almost too easy You can use every combination if n, h, s, and l you want, not counting the really stupid ones. For example, there is NOT a stolh() (Short to Long Host) functionnot at this party, anyway.But there are: htons()Host to Network Short htonl()Host to Network Long ntohs()Network to Host Short ntohl()Network to Host Long Now, you may think youre wising up to this. You might think, What do I do if I have to change byte order on a char? Then you might think, Uh, never mind. You might also think that since your 68000 machine already uses network byte order, you dont have to call htonl() on your IP addresses. You would be right, BUT if you try to port to a machine that has reverse network byte order, your program wi ll fail. Be portable! This is a Unix world!Remember: put your bytes in Network Order before you put them on the network. A final point: why do sin_addr and sin_port need to be in Network Byte Order in a struct sockaddr_in, but sin_family does not? The answer: sin_addr and sin_port get encapsulated in the packet at the IP and UDP layers, respectively. Thus, they must be in Network Byte Order. However, the sin_family field is only used by the kernel to determine what type of address the structure contains, so it must be in Host Byte Order. Also, since sin_family does not get sent out on the network, it can be in Host Byte Order.IP Addresses and How to Deal With Them Fortunately for you, there are a bunch of functions that allow you to manipulate IP addresses. No need to figure them out by hand and stuff them in a long with the h_addr); bzero(;(their_addr. sin_zero), 8); /* zero the rest of the struct */ if ((numbytes=sendto(sockfd, argv[2], strlen(argv[2]), 0, (struct sockaddr *);thei r_addr, sizeof(struct sockaddr))) == -1) { perror(sendto); exit(1); } printf(sent %d bytes to %s ,numbytes,inet_ntoa(their_addr. sin_addr)); close(sockfd); return 0; } And thats all there is to it!Run listener on some machine, then run talker on another. Watch them communicate! Fun G-rated excitement for the entire nuclear family! Except for one more tiny detail that Ive mentioned many times in the past: connected datagram sockets. I need to talk about this here, since were in the datagram section of the document. Lets say that talker calls connect() and specifies the listeners address. From that point on, talker may only sent to and receive from the address specified by connect(). For this reason, you dont have to use sendto() and recvfrom(); you can simply use send() and recv().Blocking Blocking. Youve heard about itnow what the hell is it? In a nutshell, block is techie jargon for sleep. You probably noticed that when you run listener, above, it just sits there until a packet arrives. What happened is that it called recvfrom(), there was no data, and so recvfrom() is said to block (that is, sleep there) until some data arrives. Lots of functions block. accept() blocks. All the recv*() functions block. The reason they can do this is because theyre allowed to. When you first create the socket descriptor with socket(), the kernel sets it to blocking.If you dont want a socket to be blocking, you have to make a call to fcntl(): #include #include . . sockfd = socket(AF_INET, SOCK_STREAM, 0); fcntl(sockfd, F_SETFL, O_NONBLOCK); . . By setting a socket to non-blocking, you can effectively poll the socket for information. If you try to read from a non-blocking socket and theres no data there, its not allowed to blockit will return -1 and errno will be set to EWOULDBLOCK. Generally speaking, however, this type of polling is a bad idea. If you put your program in a busy-wait looking for data on the socket, youll suck up CPU time like it was going out of style.A more elegant solution for checking to see if theres data waiting to be read comes in the following secti on on 21 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html select(). select()Synchronous I/O Multiplexing This function is somewhat strange, but its very useful. Take the following situation: you are a server and you want to listen for incoming connections as well as keep reading from the connections you already have. No problem, you say, just an accept() and a couple of recv()s. Not so fast, buster!What if youre blocking on an accept() call? How are you going to recv() data at the same time? Use non-blocking sockets! No way! You dont want to be a CPU hog. What, then? select() gives you the power to monitor several sockets at the same time. Itll tell you which ones are ready for reading, which are ready for writing, and which sockets have raised exceptions, if you really want to know that. Without any further ado, Ill offer the synopsis of select(): #include #include #include int select(int n umfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);The function monitors sets of file descriptors; in particular readfds, writefds, and exceptfds. If you want to see if you can read from standard input and some socket descriptor, sockfd, just add the file descriptors 0 and sockfd to the set readfds. The parameter numfds should be set to the values of the highest file descriptor plus one. In this example, it should be set to sockfd+1, since it is assuredly higher than standard input (0). When select() returns, readfds will be modified to reflect which of the file descriptors you selected is ready for reading. You can test them with the macro FD_ISSET(), below.Before progressing much further, Ill talk about how to manipulate these sets. Each set is of the type fd_set. The following macros operate on this type: FD_ZERO(fd_set *set) clears a file descriptor set FD_SET(int fd, fd_set *set) adds fd to the set FD_CLR(int fd, fd_set *set) removes fd fro m the set FD_ISSET(int fd, fd_set *set) tests to see if fd is in the set Finally, what is this weirded out struct timeval? Well, sometimes you dont want to wait forever for someone to send you some data. Maybe every 96 seconds you want to print Still Going to the terminal even though nothing has happened.This time structure allows you to specify a timeout period. If the time is exceeded and select() still hasnt found any ready file descriptors, itll return so you can continue processing. The struct timeval has the follow fields: struct timeval { int tv_sec; /* seconds */ int tv_usec; /* microseconds */ }; 22 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html Just set tv_sec to the number of seconds to wait, and set tv_usec to the number of microseconds to wait. Yes, thats microseconds, not milliseconds.There are 1,000 microseconds in a millisecond, and 1,000 milliseconds in a second. Thus, th ere are 1,000,000 microseconds in a second. Why is it usec? The u is supposed to look like the Greek letter Mu that we use for micro. Also, when the function returns, timeout might be updated to show the time still remaining. This depends on what flavor of Unix youre running. Yay! We have a microsecond resolution timer! Well, dont count on it. Standard Unix timeslice is 100 milliseconds, so youll probably have to wait at least that long, no matter how small you set your struct timeval.Other things of interest: If you set the fields in your struct timeval to 0, select() will timeout immediately, effectively polling all the file descriptors in your sets. If you set the parameter timeout to NULL, it will never timeout, and will wait until the first file descriptor is ready. Finally, if you dont care about waiting for a certain set, you can just set it to NULL in the call to select(). The following code snippet waits 2. 5 seconds for something to appear on standard input: #include #incl ude #include #define STDIN 0 /* file descriptor for standard input */ main() { struct timeval tv; fd_set readfds; tv. v_sec = 2; tv. tv_usec = 500000; FD_ZERO(;readfds); FD_SET(STDIN, ;readfds); /* dont care about writefds and exceptfds: */ select(STDIN+1, ;readfds, NULL, NULL, ;tv); if (FD_ISSET(STDIN, ;readfds)) printf(A key was pressed! ); else printf(Timed out. ); } If youre on a line buffered terminal, the key you hit should be RETURN or it will time out anyway. Now, some of you might think this is a great way to wait for data on a datagram socketand you are right: it might be. Some Unices can use select in this manner, and some cant. You should see what your local man page says on the matter if you want to attempt it.One final note of interest about select(): if you have a socket that is listen()ing, you can check to see if there is a new connection by putting that sockets file descriptor in the readfds set. And that, my friends, is a quick overview of the almighty select() function. More References 23 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html Youve come this far, and now youre screaming for more! Where else can you go to learn more about all this stuff? Try the following man pages, for starters: ocket() bind() connect() listen() accept() se nd() recv() sendto() recvfrom() close() shutdown() getpeername() getsockname() gethostbyname() gethostbyaddr() getprotobyname() fcntl() select() perror() Also, look up the following books: Internetworking with TCP/IP, volumes I-III by Douglas E. Comer and David L. Stevens. Published by Prentice Hall. Second edition ISBNs: 0-13-468505-9, 0-13-472242-6, 0-13-474222-2. There is a third edition of this set which covers IPv6 and IP over ATM. Using C on the UNIX System by David A. Curry. Published by OReilly ; Associates, Inc. ISBN 0-937175-23-4.TCP/IP Network Administration by Craig Hunt. Published by OReilly Associates, Inc. ISBN 0-937175-82-X. TCP/IP Illustrated, volumes 1-3 by W. Richard Stevens and Gary R. Wright. Published by Addison Wesley. ISBNs: 0-201-63346-9, 0-201-63354-X, 0-201-63495-3. Unix Network Programming by W. Richard Stevens. Published by Prentice Hall. ISBN 0-13-949876-1. On the web: BSD Sockets: A Quick And Dirty Primer (http://www. cs. umn. edu/~bentlema/unix/has o ther great Unix system programming info, too! ) Client-Server Computing (http://pandonia. canberra. edu. au/ClientServer/socket. html)Intro to TCP/IP (gopher) 24 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html (gopher://gopher-chem. ucdavis. edu/11/Index/Internet_aw/Intro_the_Internet/intro. to. ip/) Internet Protocol Frequently Asked Questions (France) (http://web. cnam. fr/Network/TCP-IP/) The Unix Socket FAQ (http://www. ibrado. com/sock-faq/) RFCsthe real dirt: RFC-768 The User Datagram Protocol (UDP) (ftp://nic. ddn. mil/rfc/rfc768. txt) RFC-791 The Internet Protocol (IP) (ftp://nic. ddn. mil/rfc/rfc791. txt)RFC-793 The Transmission Control Protocol (TCP) (ftp://nic. ddn. mil/rfc/rfc793. txt) RFC-854 The Telnet Protocol (ftp://nic. ddn. mil/rfc/rfc854. txt) RFC-951 The Bootstrap Protocol (BOOTP) (ftp://nic. ddn. mil/rfc/rfc951. txt) RFC-1350 The Trivial File Transfer Protocol (TFT P) (ftp://nic. ddn. mil/rfc/rfc1350. txt) Disclaimer and Call for Help Well, thats the lot of it. Hopefully at least some of the information contained within this document has been remotely accurate and I sincerely hope there arent any glaring errors. Well, sure, there always are. So, if there are, thats tough for you.Im sorry if any inaccuracies contained herein have caused you any grief, but you just cant hold me accountable. See, I dont stand behind a single word of this document, legally speaking. This is my warning to you: the whole thing could be a load of crap. But its probably not. After all, Ive spent many many hours messing with this stuff, and implemented several TCP/IP network utilities for Windows (including Telnet) as summer work. Im not the sockets god; Im just some guy. By the way, if anyone has any constructive (or destructive) criticism about this document, please send mail to [emailprotected] csuchico. du and Ill try to make an effort to set the record straight. I n case youre wondering why I did this, well, I did it for the money. Hah! No, really, I did it because a lot of people have asked me socket-related questions and when I tell them Ive been thinking about putting together a socket page, they say, cool! Besides, I feel that all this hard-earned knowledge is going to waste if I cant share it with others. WWW just happens to 25 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html be the perfect vehicle.I encourage others to provide similar information whenever possible. Enough of thisback to coding! 😉 Copyright  © 1995, 1996 by Brian Beej Hall. This guide may be reprinted in any medium provided that its content is not altered, it is presented in its entirety, and this copyright notice remains intact. Contact [emailprotected] csuchico. edu for more information. 26 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Da teien/Manualz/not ad ramming; Using Internet Sockets/net. htmlBeejs Guide to Network Programming Using Internet Sockets Version 1. 5. 4 (17-May-1998) [http://www. cst. csuchico. edu/~beej/guide/net] Intro Hey! Socket programming got you down? Is this stuff just a little too difficult to figure out from the man pages? You want to do cool Internet programming, but you dont have time to wade through a gob of structs trying to figure out if you have to call bind() before you connect(), etc. , etc. Well, guess what! Ive already done this nasty business, and Im dying to share the information with everyone! Youve come to the right place. This document should give the average competent C programmer the edge s/he needs to get a grip on this networking noise. AudienceThis document has been written as a tutorial, not a reference. It is probably at its best when read by individuals who are just starting out with socket programming and are looking for a foothold. It is certainly not the complete guide to sockets programming, by any means. Hopefully, though, itll be just enough for those man pages to start making sense 🙂 Platform and Compiler Most of the code contained within this document was compiled on a Linux PC using Gnus gcc compiler. It was also found to compile on HPUX using gcc. Note that every code snippet was not individually tested. Contents: What is a socket?Two Types of Internet Sockets Low level Nonsense and Network Theory structsKnow these, or aliens will destroy the planet! Convert the Natives! IP Addresses and How to Deal With Them socket()Get the File Descriptor! bind()What port am I on? connect()Hey, you! listen()Will somebody please call me? 1 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html accept()Thank you for calling port 3490. send() and recv()Talk to me, baby! sendto() and recvfrom()Talk to me, DGRAM-style close() and shutdown()Get outta my face! etpeername()Who are you? gethostname()Who am I? DNSYou say whitehouse. gov, I say 198. 137. 240. 100 Client-Server Background A Simple Stream Server A Simple Stream Client Datagram Sockets Blocking select()Synchronous I/O Multiplexing. Cool! More references Disclaimer and Call for Help What is a socket? You hear talk of sockets all the time, and perhaps you are wondering just what they are exactly. Well, theyre this: a way to speak to other programs using standard Unix file descriptors. What? Okyou may have heard some Unix hacker state, Jeez, everything in Unix is a file! What that person may have been talking about is the fact that when Unix programs do any sort of I/O, they do it by reading or writing to a file descriptor. A file descriptor is simply an integer associated with an open file. But (and heres the catch), that file can be a network connection, a FIFO, a pipe, a terminal, a real on-the-disk file, or just about anything else. Everything in Unix is a file! So when you wan t to communicate with another program over the Internet youre gonna do it through a file descriptor, youd better believe it. Where do I get this file descriptor for network communication, Mr.Smarty-Pants? is probably the last question on your mind right now, but Im going to answer it anyway: You make a call to the socket() system routine. It returns the socket descriptor, and you communicate through it using the specialized send() and recv() (man send, man recv) socket calls. But, hey! you might be exclaiming right about now. If its a file descriptor, why in the hell cant I just use the normal read() and write() calls to communicate through the socket? The short answer is, You can! The longer answer is, You can, but send() and recv() offer much greater control over your data transmission. What next? How about this: there are all kinds of sockets. There are DARPA Internet addresses (Internet Sockets), path names on a local node (Unix Sockets), CCITT X. 25 addresses (X. 25 Sockets that you can safely ignore), and probably many others depending on which Unix flavor you run. This document deals only with the first: Internet Sockets. Two Types of Internet Sockets 2 of 26 12. 03. 99 01:21 Beejs Guide to Network Programming file:///C|/Eigene Dateien/Manualz/not ad ramming; Using Internet Sockets/net. html Whats this? There are two types of Internet sockets? Yes. Well, no. Im lying.There are more, but I didnt want to scare you. Im only going to talk about two types here. Except for this sentence, where Im going to tell you that Raw Sockets are also very powerful and you should look them up. All right, already. What are the two types? One is Stream Sockets; the other is Datagram Sockets, which may hereafter be referred to as SOCK_STREAM and SOCK_DGRAM, respectively. Datagram sockets are sometimes called connectionless sockets (though they can be connect()d if you really want. See connect(), below. Stream sockets

Friday, March 20, 2020

The Burger Boy

The Burger Boy The case study is about a fast food restaurant experiencing several problems that have affected its productivity. Workers have different responsibilities. However, due to the absence of two employees, some of them are forced to work more. The problems are indicative of the poor working conditions at fast food restaurants.Advertising We will write a custom case study sample on The Burger Boy specifically for you for only $16.05 $11/page Learn More Employees are poorly compensated even though they serve a large number of customers especially during breakfast and lunch hours thus overworking. Employees yell at each other because they are under pressure while doing their job. The Burger Boy has experienced several problems that have affected the output, efficiency, and effectiveness of the employees. In addition, these problems strain relationships between the employees. They include the lack of employee motivation, interpersonal conflicts, low morale, poor comm unication, poor performance, poor leadership, and employee dissatisfaction. Some employees do multiple jobs due to the lack of clear distribution of duties and employee absenteeism. Poor communication among the employees causes interpersonal conflicts and poor leadership. The employees yell at each other and the manager treats them disrespectfully. There is also a lack of job evaluation because the employees receive low compensation even though they overwork. The manager does not hire additional employees to reduce the workload. The number of employees required for Friday rush is 13. However, only 8 are present, and moreover they overwork without the additional payment. Most of these problems are associated with compensation. They include the lack of motivation, poor communication, interpersonal conflicts, disgruntlement, and poor performance. One of the most effective methods of motivating employees is offering them adequate compensation based on the amount of work done. However, t he employees at the Burger Boy are poorly compensated even though they overwork. For example, due to absenteeism, some employees are forced to help their colleagues. The manager (Otis) breaches the psychological contract by declining to let Marge go home.Advertising Looking for case study on business economics? Let's see if we can help you! Get your first paper with 15% OFF Learn More He declines to let her leave because there are many customers who need services. The employees dissatisfaction due to low compensation is also a cause of poor communication. Interpersonal conflicts between the employees emanate from poor communication. They shout at each other because they are in bad moods. Their low productivity is evident from the amount of time it takes to serve a single customer. Usually, it takes two minutes and thirty second but they are taking three minutes and five seconds. This problem has also resulted from understaffing. Instead of the thirteen emplo yees that work during Friday rush, only eight are present. One of the signs of poor compensation is the decline in the employee morale and the conflicts among employees. Rewards are important because they increase the employees’ motivation and consequently increase their performance. However, the employees at the Burger Boy do not receive any kind of rewards. Rewards could help to solve several problems including job dissatisfaction, low morale, and poor quality of work. Employee dissatisfaction is evident from the employees’ tendency to complain about their jobs. Many employees are dissatisfied because they overwork and are undercompensated. For example, Marge is forced to abdicate her work because her shift is over even though more customers are trickling in. Besides, Leon complains to Otis and says that he is vexed by the inefficiency at the workplace because the employees who work during lunch shift do not stock items as required. In response, Otis tells Leon that he is tired of his whining and storms out of the office and goes home. He also complains of low wages. Otis is a poor leader because communication between him and employees is very poor. Poor leadership leads to negative employee attitudes and relationships. These problems can be solved by establishing employee reward programmes. To improve employee morale, it is important for employers to establish fair compensation packages and reward programmes. Otherwise, productivity, efficiency, and job satisfaction decline considerably.Advertising We will write a custom case study sample on The Burger Boy specifically for you for only $16.05 $11/page Learn More Additional hours of work are incentives that employers use to reward those employees whose performance is exceptional. It is similar to overtime. However, it involves working for additional hours besides overtime. Additional hours of work rewards are only effective if an employee is comfortable with the compen sation offered. Chuck was not happy with working for 30 hours per week because he was dissatisfied with his job and had low morale. Chuck complains about the low staffing because he is aware that he will do more work than it is required of him. With the amount of work done at the pay window, Chuck was probably not happy with working 33 hours per week. Newman was happy working 20 hours per week probably because he was satisfied with his work. In addition, he was comfortable with his compensation. Schedules may be used as rewards by allowing employees to work during their most favorable hours. Employers could allow employees to set their own working hours depending on availability and commitment to other responsibilities such as family and education. In addition, the employers could create flexible schedules that give their employees enough breaks and rest. It is important for the employees to get enough rest in order to avoid burnouts and stress that reduce performance.

Tuesday, March 3, 2020

Shepard Fairey, the Controversial Street Artist

Shepard Fairey, the Controversial Street Artist Often described as a Street artist, Shepard Faireys name first began to appear in the news for wheat pasting (a method of adorning public spaces with the artists own posters by way of a water and wheat mixture- like a wallpaper paste), sticker tagging, and the numerous accompanying arrests that now comprise his official criminal record. Hes best known for his painting of Obama in 2008  titled Hope  and his poster from 1992 titled Obey, which inspired a clothing line of the same name. I think the Obey icon image finds a balance between goofy and creepy, humorous and monolithic. I consider the image the counter-culture Big Brother. Id like to think of it as a sign or symbol that people are watching Big Brother as well. Ive had people ranging from anarchists to the president of the National Reserve Bank embrace my work and I think the more diverse the audience is, the more potential for interesting dialogue there is.- Stepard  Fairey Early Life and Training Shepard Fairey was Frank Shepard Fairey born on February 15, 1970, in Charleston, South Carolina. The son of a physician, Shepard Fairey fell in love with making art at age 14. After graduating from the prestigious Idyllwild School of Music and the Arts in Idyllwild, California in 1988, he was accepted at the Rhode Island School of Design. (If youre not familiar with this fine institution, RISD is almost ridiculously hard to get into and enjoys a sterling reputation as a training ground for working artists.) Fairey graduated in 1992 with a B.F.A. in Illustration. From the Street to Art While attending RISD, Fairey had a part-time job in a Providence skateboarding shop. The marginalized, underground culture there (where styles are out as soon as theyre in) synthesized with that rarified art school culture and Faireys ongoing interests in punk music and stenciling his own punk music t-shirts. Everything meshed on the day a friend asked him how to create a stencil. Fairey demonstrated with a newspaper ad for a professional wrestling match featuring Andre the Giant which was the most banal image he could have grabbed. Tantalizing what if possibilities began to cross Faireys mind. It came to pass that Fairey, who had only recently become aware of Graffiti Art, took his Obey stencils and stickers to the streets. Andre the Giant famously gained a posse and Faireys name was launched. Controversy Around Faireys Work Fairey has often been accused of plagiarizing other artists work. In some cases, even casual examination of these claims shows almost verbatim copying with little transformation. While some of the older, political propaganda works are in the public domain, others are not. The real issue seems to be that Fairey copyrights these appropriations, enforces his copyrights and profits from them. There are a lot of different people who’s  [sic]  work I like that arent necessarily aesthetic influences, but conceptual- and there are some that are aesthetic. I’m inspired by John VanHammersfeld who did a lot of psychedelic poster graphics and one of my earliest Obey Giant graphics was my knock of his iconic Hendrix graphic. My work is very much a melting pot of a lot of different influences.- Stepard  Fairey Fairey also disappointed a segment of his fans by not remaining a cult figure and beginning to make money as an artist. Conversely, his messages calling for social and political change are sincere, he donates heavily to causes and he keeps a staff of assistant artists gainfully employed. Many parallels can be drawn between Faireys image sources and those of Andy Warhol, who is now celebrated in the art world. Only time will tell if Fairey attains Warholian status, but he gained a lasting place in history for the HOPE poster during Barack Obamas 2008 Presidential campaign. Sources Fairey, Shepard. E Pluribus Venom.Berkeley : Gingko Press, 2008. Fairey, Shepard. Obey: Supply Demand : The Art of Shepard Fairey.Berkeley : Gingko Press, 2006. MacPhee, Josh. Stencil Pirates.New York : Soft Skull Press, 2004. Shepard Fairey (biography at thegiant.org)Retrieved 27 January 2009