Monday, June 1, 2020

Female Entrepreneurs Use Instagram To Market Their Cosmetic Business - 2750 Words

How Young Female Entrepreneurs Use Instagram To Market Their Cosmetic Business (Dissertation Sample) Content: INSTAGRAM MARKETING RESEARCHBy (Name)Course:Instructor:Institution:City and State:Date:Table of ContentsIntroduction........................................................................................................................3Literature Review...............................................................................................................4Research Question..........................................................................................6Research Objectives...........................................................................................................6Research Methodology.......................................................................................................7Research Approach..............................................................................................................8 Data Collection ................................................................................................................ .. 8Instrument.............................................................................................................................9 Sampling Method.................................................................................................................9Scopus study methods.........................................................................................................10Quality Issues......................................................................................................................10Research ethics 11Research philosophy 12Data Analysis........................................................................................................................13Conclusion........................................................................................................................... 15References........................................................................................................................... 16Young Women in Bus iness Using InstagramINTRODUCTIONInternet-based technologies and digital philosophy have developed to be an essential part of our day-to-day activities. This topic is at the topmost of the schedule for many investigators and policy creators. Social media offers a conventional of computer-mediated implements that permit people or businesses to generate, share, or interchange data, career benefits, concepts, and photographs/videos in computer-generated societies and networks (ALBARRAN, 2013). They present considerable and universal changes to relations between companies, establishments, groups, and personalities. Specifically, social media makes new techniques of interacting and doing business possible, centered on inventive notions such as distribution, association, and co-creation (HERMAN, BUTOW WALKER, 2018). This research aims to underwrite to this developing subject matter through a literature assessment on females in business and Instagram to comprehend whether studies piloted so far have spoken deeply on these subjects: in what way and why are females entrepreneurs exhausting Instagram? Do they use it for advertising relations, interacting or private connections?Nevertheless, this is a not a popular topic, with implications on organization and business that are still new. Therefore, it is essential to know how Instagram can enable, endorse, and maintain dealings for women in business, and if they are capable of taking complete advantage of them.LITERATURE REVIEWIn The social media industries, the scholar reviews places in a proof that there is a deficiency of study on the use of Instagram by women in business in the United Kingdom. This different article may clarify the method adopted in studying effects related to the use of Instagram by women entrepreneurs, in addition to the main subjects developing from these evaluations. Instagram can create new openings for women entrepreneurs, and inspire the formation of new companies run by women, appreciations to their flexibility and their features.The Summary: How to Use Visuals, Videos and Social Media to Market Your Brand article the authors examines how Womens demotion, sidelining and lack of annexation have the positive effect of Instagrams on women entrepreneurs acknowledgments to their agility and connectivity influence. This research contributes to the addition of style on entrepreneurship researchers and proposes a new viewpoint applied to issues of great implication. The main practical effect is to improve understanding in the area of femininity in the organization by reassessing communication and interacting activities using the Instagram. There is an increasing number of young women who venture into the corporate world using social media as their main marketing and sales platform. This segment incorporates a detailed analysis of the involvement of young females in business and the way they have decided to embrace social media and as a technique to boost their micro businesses . The notion of the network for females in business is the formation of an essential connection between family work, and the public that often agrees with the key reason to set up a business. This study underwrites to the addition of works on women in business studies, and offers a new viewpoint applied to a focus of high impact such as Instagram.In the Facebook advertising article, the study was aimed at understanding whether social media is a more successful entrepreneurship for small business investments, especially those owned by women. It focused on the benefits a young entrepreneur reaps from using social media as opposed to traditional media. Social media is more profitable and economically feasible to small scale entrepreneurs compared to traditional media in terms of its capacity to reach a massive range of consumers. According to the study, social media avails small-scale businesses and entrepreneurs first hand and in time information which is cheaply available. This the l east that could be said about traditional media such as television and newspapers which are very expensive and thus not favorable for small-scale and start-up businesses. Although Facebook is the mother of all, many small scale entrepreneurs prefer Instagram for conducting their businesses because they can connect to people they do not even now. The research literature evaluation puts in ratification that this is a fresh issue, which provides us the opportunity to pinpoint new developments and future guidelines for the study. The increasing number of women who have risen and decided to embark on entrepreneurship through social media has gone up tremendously over the years. This study focuses on bringing out the way the modern woman has embraced social media as her platform for both formal and informal business investments. Women are known to be empathic and thus are likely to study their customers well and relate their products and services to their customers, that is why women entr epreneurship through social media is such a thriving venture. The study cites out women such as Caroline Ceniza-Levine who saw her social media business grow by a whopping 600% in her first three years.Branded women in U.S. television: when people become corporations examines women in business who use Instagram in their personal life and also as part of their business or decision-making roles. In their secluded life, they use Instagram to keep social contacts, to progress work-life stability and also to share individual thoughts. They also use Instagram to broaden their public network in the corporate; to promote corporation produce or brand; to incorporate clients or potential clients in product enhancement; to encourage employee teamwork and interaction. The studies focus on female entrepreneurs in micro businesses that require small capital investment and put emphasis on how women have strategically positioned themselves in the corporate world using Instagram as their driving to ol. The study will focus on not only small scale businesses such as sole proprietorships but also large scale ones such as limited liability companies. It has also been realized as a way to keep of personal relations, which can be relevant for females in business that, in many circumstances, have to mix their private life household tasks with work responsibilities. In this research, the primary focus is to research on how young women in the United Kingdom have maximized the use of the many available forms of Social Media to enhance and market the companies and the businesses in which they work for. The other forms of those social media platforms that these young women use include Facebook and Twitter.Killer Facebook ads: master cutting-edge Facebook advertising techniques also stresses on the fact that female entrepreneurship has not received the attention it deserves because even if most women venture in micro scale businesses they definitely play a role in economic growth. Accordi ng to the study, women invest in businesses that require low startup capital and are most likely to, compared to their male counterparts, perform less impressively in terms of sales. Female entrepreneurship in the modern economy is mainly driven by technological developments which offer women the chance to provide products and services that are aimed at improving the q...

Saturday, May 16, 2020

Case Study - 2091 Words

Case Study: Specific Learning Disabilities Criteria Name: Jennifer Birthdate: 12/17/92 Jennifer is a 2nd grader being referred for possible learning disabilities in reading. Jennifer has always attended Sand Hill Elementary and has not repeated a grade. She is eight years old. She has been screened for vision and hearing problems and was found to have normal vision and hearing. Her teachers have described her as cooperative and likable. She does not exhibit behavioral problems. Jennifer has a history of difficulty with early reading skill milestones. She had difficulty learning the letters of the alphabet in kindergarten as well as trouble with initial sounds, sight vocabulary and rhyming. Her overall language development was†¦show more content†¦She has been paired with a peer to assist with reading directions during work time in all subjects. She also exhibits trouble organizing her time and space and sometimes does not go back and complete unfinished work during time allotted in class. She often hands in unfinished assignments and forgets to bring homework home. When asked, she says she didn’t remember that she hadn’t finished the work. She does not use the assignment list that is posted on the blackboard every day to help her get the materials needed for homework unless the teacher goes over it with her individually. Most of the other students in her 2nd grade classroom are able to read classroom text and complete work independently. They also read books for enjoyment on their own. The reading time in her classroom consists of a block during which the teacher works with small groups and the children are expected to work quite independently when they are not working directly with the teacher. The class uses a trade book format and this is utilized across the curriculum. Students are provided with short skills building lessons in large and small groups. Most of the time spent during explicit reading instruction is targeted to helping students develop reading fluency. Jennifer also works with the Title I reading teacher during this time period for  ½ hour, three times per week. The Title I teacher has been using SRA Reading Mastery with Jennifer this year. Although she says thatShow MoreRelatedCase Studies : A Case Study Approach Essay1157 Words   |  5 PagesA case study is a specific instance that is frequently designed to illustrate a more general principle (Nisbet and Watt, 1984). Hitchock and Hughes (1995) further suggest that the case study approach is particularly valuable when the researcher has little control over evens. Case studies strives to portray ‘what it like’ to be a particular situation, to catch up reality and ‘thick description’ (Geertz, 1973) of participants’ lives experiences of, thoughts about and feelings for a situation. TheyRead MoreCase Study887 Words   |  4 PagesCHAPTER I INTRODUCTION 1.1 Reasons choose the case 1.2 The Problems The problems of this case are: 1. How would you characterize Lincoln Electric’s strategy? In this context, what is the nature of Lincoln’s business and upon what bases does this company compete? 2. What are the most important elements of Lincoln’s overall approach to organization and control that help explain why this company is so successful? How well do Lincoln’s organization and control mechanismsRead MoreBusiness Case Study : Business Case Studies997 Words   |  4 PagesWriting Business Case Studies How to Write Business Case Studies The objective of this part of the course is to use your case study to help you solve real company problems and to make the learning more relevant to your experience. The Business Case Study you are being asked to start today will provide information for yourself and the class to permit constructive feedback. You will have to use all of your research, writing and analytical skills to write your Company Case Study. You must give enoughRead MoreCase Study148348 Words   |  594 Pages978-0-273-73552-6 (web) All rights reserved. Permission is hereby given for the material in this publication to be reproduced for OHP transparencies and student handouts, without express permission of the Publishers, for educational purposes only. In all other cases, no part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise without either the prior written permission of the Publishers orRead MoreCase Studies13817 Words   |  56 PagesCASE STUDY #1 A Job Search Dilemma Eric, a second-semester senior, is looking for a job. Anxious about finding work in the worst economy in decades, he sends out scores of resumes for a wide variety of positions. The first call he gets is for a position that doesnt really interest him, but he figures he should be open to every opportunity. He schedules an interview, which he aces. In fact, the recruiter offers Eric the job on the spot. He would like Eric to start as soon as possible. Should EricRead MoreCase Study 8985 Words   |  4 PagesCase Study 8 Based on the January through June 2010 cash budget, what is the maximum monthly loss during the six-month planning period? What is the maximum cumulative borrowing balance? (For purposes of this question, disregard any interest payments on short-term bank loans or interest received from investing surplus funds.) Maximum monthly loss is in June: -$60,750. The maximum cumulative borrowing balance is $99,000 in February. What does the monthly cash budget reveal that indicatesRead MoreCase Study : The Angel 1089 Words   |  5 Pages Case Study #1 The Angel, 1997 Susan Meeks, an alias, woke to what she thought was the middle of the afternoon. A bright yellowish light was shining through the west window of her travel trailer. An other world being was in the room and was as tall as the ceiling of the trailer. She went to the bathroom where she washed her face with cold water and stayed in there long enough to smoke a cigarette. When she went back to the bedroom the being was still there. The being showed her futureRead MoreThe Case Study Of The Company1468 Words   |  6 PagesOverview of Case Study In the case study by Spector titled, Transferring Innovation Across National Boundaries, (Spector, 2012) company named Minnesota Biolabs (MB) provided laboratories with a quality test for contamination of injectable medications. This test required the use of live rabbits that led to the rabbit’s death after the test. The company was headquartered in Minneapolis, however they were organized with four, somewhat independent, national units in Europe and Japan, each run by aRead MoreLaw of Case Studies1514 Words   |  7 PagesZulfatah Arif SCM-019741 Work Psychology in Communication, Writing and Reporting COM 2153 Mr Haji Adenan Case Studies An Unmotivated Building Inspector Case Study By: Zulfatah Arif 1) Review the motivation theories discussed in this chapter. How would each one describe and explain the problems with Simon Lucas’s motivation? The theories that would be relevant to the problems with Simon Lucas’ motivation would be the McClelland’s Need Theory and Herzberg’s Two-Factor Theory.Read MoreCase Study Essay1116 Words   |  5 PagesCase Study Objective The Case will focus on issues related to the cultural aspect of international business; sustainable business practices including CSR issues; foreign investment; and the benefits of regional integration for the countries within, and companies doing business in, that region.   The case study analysis will be completed on an individual basis. Instructions THE CASE: Kaizer Consulting Kaizer Consulting is an international management consulting firm that specializes in business strategy

Wednesday, May 6, 2020

Medieval Music And England During The Time Of 1066-1500

Medieval Music in England from 1066-1500s What significant developments or achievements from Medieval Music in England during the time of 1066-1500 CE has had an impact on today’s music and how? The Medieval Times had a lot of trading and invasions of new lands. Countries exchanged ideas to other countries, introducing new discoveries and inventions. During Medieval England, music was a current and changing development, with composers changing their music all the way to the growth and decisions of the Catholic Church. But without other foreign countries and kingdoms such as France and Germany, todays would have not been what it is now. The Importance of Medieval Music in England Music was a very important asset to the peoples’ society. According to historians, the medieval period was the beginning of the unbroken tradition of notated Western music. Music was the one thing that all classes could enjoy, royals, nobles, women, slaves, anyone could listen to music being played out on the streets. Music was used in cathedrals and abbeys, dances and was even part of poetry. Most of the poetry from the Medieval Period known today were sung in front of crowds during events and festivals. Vocal music was very important in churches and worshipping. Back in the medieval time, there weren’t any radios, so all of the music was played live. Festivals, celebrations and the holiday season were very popular times for music. During an important holiday, Mayday, the dancers danced to highShow MoreRelatedHistory of British Literature3343 Words   |  14 PagesLate Medieval Period 14th Century British Literature 14th and 15th were period of transition from feudalism to pre-industrial era. A time of political, social and ideological conflicts; England was in war with France (the hundred year war 1337-1453 Edward’s claim to the French throne and attempt to bring England, Gascony and Flanders under unified political control). The defeats in France lead to deepening the internal crisis. The decline in agriculture together with the rise in the populationRead MoreThe Metrics Of English Literature4721 Words   |  19 Pageseven 50 years from now, maybe we will not even recognise our language. The emphasis is on the connection between the different stages of English. This connection mainly being the tone and rhymes of the language that society becomes accustomed to over time as other influences change society. Sylvia: I do not disagree with you but if we were here to talk about history I would still be at home reading my textbooks. You see, though the English language is a daily functional tool, a form of communicationRead MoreArt History7818 Words   |  32 Pages#61607; Organized Religion • Before civilization, there was just shamanism #61607; Monumental architecture • Great Wall, Coliseum o Cradles of Civilization #61607; Cannot trace civilization back any further #61607; All started around same time #61607; Alls started independently #61607; Mesopotamia Ââ€" present day Iraq • Earliest Cradle • Around 4,000BC #61607; Egypt • Around 3,000BC #61607; Southern India • Around 3,000BC #61607; China • Around 2,800BC • Composed of two separated

Tuesday, May 5, 2020

Mysticism in Wordsworth Poetry Sample Essay Example For Students

Mysticism in Wordsworth Poetry Sample Essay William Wordsworth is an high mysterious poet of the Romantic Age with an surprisingly elusive head and a aberrant capacity for showing personal beliefs and ideas. Wordsworth was a true mystic. His mystical experiences are chiefly revealed in the context of his intervention of nature. Wordsworth neer confined his poetry within the graphic portraiture of the sights. sounds. olfactory properties. and motions of assorted elements of nature. He aimed at achieving something higher and divine and go forthing behind a record of his mystical experiences in nature and human life in his poesy. So his poesy is non merely an artistic encapsulation of lovely and placid facets of nature but besides a comprehensive history of his mystical experiences. Wordsworth’s mysticism is singular for its brooding temper and pantheistic construct of nature. It is moulded by the belief that nature is a life being and the brooding topographic point of God. Nature is the agencies through which a adult male can come into contact with God. Wordsworth maintains that a Godhead spirit pervades through all the objects of nature. As a true pantheist he besides says that all is God and God is all. Many of his verse forms can be studied with this contextual consideration. This perceptual experience is peculiarly reverberated in Tintern Abbey. where he says with great devotedness: â€Å"†¦And I have felt A presence that disturbs me with the joyOf elevated ideas ; a sense sublimeOf something for more deeply infused.Whose home is the visible radiation of the scene Sun.And the unit of ammunition ocean and the life air.And the bluish sky. and in the head of adult male: †He finds the being of God even in the head of adult male. Wordsworth upholds that there is a pre-arranged harmoniousness between the head of adult male and the spirit in nature. which enables adult male to organize a relationship or communicating with nature. The relationship is materialised when the head of adult male forms a affinity with the ideas of nature. And it is this affable and rational junction between adult male and nature that helped to determine his belief that nature has the power to learn and educate human existences. Man accomplishes flawlessness and practical cognition through the instruction he receives from nature. He believes that the individual who doesn’t receive instruction from nature is worthless and his life is unsuccessful. The poet considers nature as a big beginning of cognition. He besides believes that nature is the nurse and the defender of the world. Nature’s benignancy considers merely the public assistance of human existences. In his words. nature is: â€Å"The ground tackle of my purest ideas. the nurse. The usher. the defender of my bosom. and psyche.Of all my moral being. †In Wordsworthian belief. nature is capable of relieving the anguished head of adult male. The beautiful and coltish facets of nature are an infinite beginning for mending power. The material life sometimes become so blunt and painful that human existences loose the aspiration for life. When life becomes such intolerable so the Sweet and fond contact with nature can easy drive away the cloud of cynicism from the head of the spectator of nature. The noise and perturbation of the town or metropolis life may do human life unbearable but even the remembrances of nature in some alone room can extinguish the load of devastation. anxiousness and asphyxiation: â€Å"But frequently. in lonely suites. and ‘mid the blare Of towns and metropoliss. I have owed to themIn hours of fatigue. esthesis Sweet.Felt in the blood and felt along the bosom ;And go throughing even into the purer headWith placid restoration†¦Ã¢â‚¬ Wordsworth. like a true mystic. sees life in all objects of nature. Harmonizing to him. every flower and cloud. every watercourse and hill. the stars and the birds that live in the thick of nature. has each their ain life. .u241914229403541318ec002079059461 , .u241914229403541318ec002079059461 .postImageUrl , .u241914229403541318ec002079059461 .centered-text-area { min-height: 80px; position: relative; } .u241914229403541318ec002079059461 , .u241914229403541318ec002079059461:hover , .u241914229403541318ec002079059461:visited , .u241914229403541318ec002079059461:active { border:0!important; } .u241914229403541318ec002079059461 .clearfix:after { content: ""; display: table; clear: both; } .u241914229403541318ec002079059461 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #95A5A6; } .u241914229403541318ec002079059461:active , .u241914229403541318ec002079059461:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #2C3E50; } .u241914229403541318ec002079059461 .centered-text-area { width: 100%; position: relative ; } .u241914229403541318ec002079059461 .ctaText { border-bottom: 0 solid #fff; color: #2980B9; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u241914229403541318ec002079059461 .postTitle { color: #FFFFFF; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u241914229403541318ec002079059461 .ctaButton { background-color: #7F8C8D!important; color: #2980B9; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://artscolumbia.org/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u241914229403541318ec002079059461:hover .ctaButton { background-color: #34495E!important; } .u241914229403541318ec002079059461 .centered-text { display: table; height: 80px; padding-left : 18px; top: 0; } .u241914229403541318ec002079059461 .u241914229403541318ec002079059461-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u241914229403541318ec002079059461:after { content: ""; display: block; clear: both; } READ: Women In Math Essay PaperWordsworth honours even the simplest and the most ordinary objects of nature and human life. For him nil is average or low. since everything that is present in the existence is touched by godly life. To reason we ought to state that Wordsworth neer looked at nature like the manner we do. With great devotedness and enthusiasm. he sought to read the profoundest significance of human life in nature. In the manner of making so he forged himself as a great poet of nature with a true mystical vision.

Saturday, April 18, 2020

Turnaround Strategy free essay sample

The two broad turnaround strategies that may be followed by Public and Private companies are Strategic and Operating. Strategic turnarounds can be branched into activities that comprises of a change in business strategy for competing in the same business and those that involve for entering a new business or businesses. Operating strategies does not involve altering the business level strategies and usually focuses on increasing revenues, decreasing cost, decreasing assets or a combination effort. Our research work mainly focuses on existing corporates that applies Strategic turnaround strategies to reverse a major decline in their performance. Repositioning Strategy Repositioning is an entrepreneurial strategy that puts its emphasis on growth and innovation. This strategy answers the declining situation in an organization by devising out a new definition of the mission and its core activities. The organization can choose to stay and become more dominant in the existing market or by diversifying itself into new markets and products. We will write a custom essay sample on Turnaround Strategy or any similar topic specifically for you Do Not WasteYour Time HIRE WRITER Only 13.90 / page In some of the cases the management may think that the current resource capabilities of a company can achieve a greater competitive advantage, if applied to a new market segment by successfully integrating and making a fit between the capabilities of the firm and the external environment. The repositioning strategy acknowledges the notion of diversification and provides an opportunity for a firm to leverage on it existing resources such as financial and technical capabilities to come up with related or unrelated products. However, the success of this strategy is highly dependent on the management to effectively select the right portfolio mix. Nike was successful in pursuing related diversification when it decided to launch beach styled sport clothing (Hurley) as a business line. The impact of this entrepreneurial strategy applied in the private sector has been researched in 11 empirical studies. Out of 11, only two of these find that the repositioning strategy has no impact on the financial recovery . From the remaining 9 studies, 7 of them has clear evidence that repositioning has a positive impact on the firms performance. Focusing on the Core Activities This turnaround relates to a particular niche or a focus strategy (Porter,1980,pp. 38–40). This strategy doesn’t involve a complete redefinition of the business but it tries to bring in a strategic change for refocusing on a particular product/market mix. Sometimes this strategy is chosen when a firm loses its focus by adding new product lines or customers while still trying to compete with its historical product/market mix. A classic extension failure exa mple would be Coca-Cola launching â€Å"New Coke† in 1985. [33] Although it was initially accepted, a backlash against â€Å"New Coke† soon emerged among consumers. Not only did Coca-Cola not succeed in developing a new brand but sales of the original flavour also decreased. Coca-Cola had to make considerable efforts to regain customers who had turned to Pepsi by focusing on its core brand. Outsourcing Outsourcing is a strategy that addresses an organization’s position within the value chain it operates. It shares some similarity with the focus strategy as this process calls for focusing on the activities where the firm is more profitable and to outsource the remainder activities to the third parties who can perform them more efficiently. Traditionally, outsourcing strategy has been applied more to the finance and Information system departments. In 2008 Chrysler made news in which it announced that several hundred technology workers would lose their jobs as it was moving with plans to outsource their IT department. The rationale behind this step was to improve the effectiveness and efficiency of the company while making it more flexible to the environmental changes. The Management Process One of the widely researched and generalized Turnaround strategy is the replacement of the current Top Management Team of the business suffering from declining performance. Alot of turnaround experts sees that replacing the CEO is one the most important ingredient for recovering a business. The rationale behind this is that the top management has a certain set of beliefs about running a business, many of which must be wrong for the current decline in performance to arise. Previous researchers who have studied the turnaround strategies have also asserted that the turnaround efforts are begun with the top management being replaced mainly due to thefact that the new management brings in a new understanding of the factors affecting a firm’s performance, enabling productive change to occur. However, regardless of the evidence provided above, not all of the turnaround strategies require a change in their top management. Some of them can be successfully accomplished through the incumbent management. The decision whether to change the current management or not are dependent on a number of factors, e. g. the causes of decline (Some decline may occur becau se of unmanageable external factors), the industrial differences as well as the firm resource situation.

Saturday, March 14, 2020

Network Programming with Sockets Essays

Network Programming with Sockets Essays Network Programming with Sockets Essay 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 w ithin 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 Socket s 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 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 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. 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 mind, 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 a re some facts: if you send 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, fi ve seconds, hell re-transmit 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 hardware (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 Lay er 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 b ear 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. ) s truct sockaddr_in { short 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 re quires careful examination 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) an d long (four bytes). These 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 byt e order, your program will 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 *);their_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 ( cs. umn. edu/~bentlema/unix/has other 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 ( 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 (TFTP) (ftp://nic. ddn. mi l/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. In 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 Dateien/Manualz/not ad r amming; Using Internet Sockets/net. htmlBeejs Guide to Network Programming Using Internet Sockets Version 1. 5. 4 (17-May-1998) [ 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? gethostn ame()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 want to communicate with another pro gram 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 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 mind, 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 send 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-transmit the packet until he finally gets an ACK. This acknowledgment procedure is very important when implementing SOCK_DGRAM applications. Low level Nonsense and Network TheorySince 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 (encapsul ated) 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 pres ent 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 hardware (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 th e 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 { short 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 si n_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 examination 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 t alk 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). These 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 net work 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 will 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 *);their_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.

Wednesday, February 26, 2020

Gross Domestic Products Essay Example | Topics and Well Written Essays - 1500 words

Gross Domestic Products - Essay Example When wage increases it would yield to higher production costs, thereby producing higher prices of goods and services and also increases the inflation rate. To station an equilibrium, unemployment rate must be consistent with the full employment rate. The interaction of supply and demand is a vital part of macroeconomics, consumer’s ability to adapt price changes and employers increasing the prices of the commodity may have several implications triggering the either inflation or stagflation. If consumers are cannot keep pace on the increasing price commodities, inflation may occur, however if employers are passing their labor cost index on consumers aiming to generate profit through price increase on commodities yet consumer can still cope up with the changes, stagflation occurs, where business did not gain anything and yet did not have any single loss. To illustrate further, we have to examine the country’s GDP of two of the world’s most prosperous nation, Austra lia, and United States. For over the past years, Australia’ economy has displayed worthily, however in 2006, it began to decline yielding only 2.5 % in real GDP. Drought, inflation, high oil prices, and economic deceleration attributed to the decreased in real GDP. (Economic and Social Survey of Asia and the Pacific 2007). Domestic demand brought for the country’s thrust. Domestic demand comprises of business investment. High capacity utilization and high corporate profits served as a catalyst for the growing business investment in Australia.... When wage increases it would yield to higher production costs, thereby producing higher prices of goods and services and also increases in the inflation rate. To station an equilibrium, unemployment rate must be consistent with the full employment rate. The interaction of supply and demand is a vital part of macroeconomics, consumer's ability to adapt price changes and employers increasing the prices of commodity may have several implications triggering the either inflation or stagflation. If consumer's are cannot keep pace on the increasing price commodities, inflation may occur, however if employers are passing their labor cost index on consumers aiming to generate profit through price increase on commodities yet consumer can still cope up with the changes, stagflation occurs, where business did not gain anything and yet did not have any single loss. To illustrate further, we have to examine the country's GDP of two of the world's most prosperous nation, Australia and United States . For over the past years, Australia' economy has displayed worthily, however in 2006, it began to decline yielding only 2.5 % in real GDP. Drought, inflation, high oil prices and economic deceleration attributed to the decreased in real GDP. (Economic and Social Survey of Asia and the Pacific 2007). Domestic demand brought for the country's thrust. Domestic demand comprises of business investment. High capacity utilization and high corporate profits served as a catalyst in the growing business investment in Australia. Capacity utilization refers to the amount pf physical capital available to firms that is in use. Firms are given ample stock of capital equipment such as machinery, office spaces, factories, computers and telecommunications as