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