A Web Backend example that runs swift development under the "Getting Started with Swift" Ubuntu compilation

Source: Internet
Author: User

This is just a demonstration of how to compile a Web backend project that runs Swift development under Ubuntu.

The project code comes from the sample code provided on Bluemix, if you have an account, you can go to your own space to download, no, you can download it through the following address:

http://download.csdn.net/detail/testcs_dn/9513395


To install the installation configuration of the environment, please refer to: Ubuntu Server installation Swift operating environment

After the environment is configured, extract the downloaded sample code:


The main code is "Main.swift", which reads as follows:

/** * Copyright IBM Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * You are not a use this file except in compliance with the License.  * Obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * unless required by applicable Law or agreed into writing, software * Distributed under the License is distributed on a "as is" BASIS, * without Warra Nties or CONDITIONS of any KIND, either express OR implied. * See the License for the specific language governing permissions and * limitations under the License. **//*** creates a simple HTTP server this listens for incoming connections on port 9080.* for each request receieved, the Server simply sends a simple Hello World message* back to the client.**/#if OS (Linux) import Glibc#elseimport Darwin#endifi Mport utilsimport foundation//Create server Socketlet address = parseaddress () Let SERVER_SOCKFD = Createsocket (address)/ /Listen on socket with queue of 5listen (SERVER_SOCKFD,5) var active_fd_set = Fd_set () print ("Server is listening on port: \ (address.port) \ n")//Initialize The set of active Socke Tsfdset (SERVER_SOCKFD, set: &active_fd_set) Let fd_setsize = Int32 (1024x768)//Generate HTTP response//Get Environment VA Riableslet environmentvars = Nsprocessinfo.processinfo (). Environmentvar responsebody = "The service can be compiled and started with the following command:

[Email protected]:/home/aven/swifttrans# Swift build[email protected]:/home/aven/swifttrans#. build/debug/ Serverserver is listening on port:9080

At compile time, you may receive the following error:

Error:unable to invoke subcommand:/usr/bin/swift-build (No such file or directory)

After the service has been successfully started, we can access it through the browser, such as:




A Web Backend example that runs swift development under the "Getting Started with Swift" Ubuntu compilation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.