Simple Localhost Server in Xcode/Swift? - swift

I am making a macos app in XCode, and I was wondering if there was a way to make it host a local server that is visible across the network.
I am trying to find a way so that it would host something on the devices's network with it's hostname/ip address, so if someone goes to http://hostname:5000 they would be able to see the response, and the app would be able to see the request, just like how hosting a local python server works. Is there any way to do this in XCode with Swift?
For example: the user presses 'start server' on their screen. The server is hosted across the network. Anytime a request is made to it, they get a notification.

Just to make you concern you may find some sample codes, including local web server inside the app.Few of them I found are:
https://github.com/ooper-shlab/MyWebViewApp-Swift
https://github.com/depoon/SwiftLocalhost
The main thing is it's just a public
, experimental code, so it's not simple, not easy to adopt, not all coding best-recommended, far from readable and may have severe bugs.But you can use it as a working example and take any parts of it into your app.

Related

capacitor app log local ip address in offline request

I would like to log the ip address in some requests. For this i would like to get the info from the network-interface in my app. As it is a offline app that replicates to couchdb and not server requests this is proving to be difficult.
i was thinking of using #capacitor/network but this plugin only tells me if there is a network connection and no infos.
Then i tried cordova-plugin-networkinterface but i could not get this plugin to work properly because it does not show in cordova.plugins like cordova-plugin-badge.It does show up in the window object as window.networkinterface.getIPAddress() but it returns "undefined".
Can someone please tell me why cordova-plugin-networkinterface does not work in capacitor (not using ionic) or a different approach.

How to use Google Action Builder with my own server

I want to develop an action to google assistant. So i red the documentation here https://developers.google.com/assistant/conversational/overview and i followed this tutorial https://www.youtube.com/watch?v=Z1hxvniJ18s
It s worked and i was allow to develop and test my app in the simulator. The problem is that when it's come to webhook i don't totaly understand how it's work. On the webhook icon i got this
The seconde one allow me to use Google cloud function and firebase but i had to add my billing account to make it available. I also get a console where i can code my fonctions and my responses.
And if i am correct, the first one allow me to connect to my own Api. But i can only enter one field that is the URL adresse and nothing else so how do i code it? Also i see everywhere people using node.js and i would like to use php is it possible?
To sum up my problem, i would like to know how i could connect my action builder to an other service(Api) than google ones? If it's possible to run my server in php and how do i interact with my google action?(I think it's by sending json back and forth but i'am not sure how to do it?) Finally i would like to know if it's possible to test it in local server with mamp and phpmyadmin for exemple to test the answer of the server?
I would be very grateful if someone could help me, show me how to set up all this.
But i can only enter one field that is the URL adresse and nothing else so how do i code it?
When you develop your webhook, you will need to have a single publicly accessible endpoint to connect with. This endpoint will receive an HTTP POST request and you will need to respond with an appropriate response.
Also i see everywhere people using node.js and i would like to use php is it possible?
Any language that can run on a web server can work. Node.js is one that is used a lot, but PHP can work just as well. You can create an actions.php file and then enter an endpoint address https://example.com/actions.php that will be called. You may need to refer to the Request and Response reference for the expected format.
if it's possible to test it in local server with mamp and phpmyadmin for exemple to test the answer of the server?
It's somewhat possible. You'll need to have some method of sending mock requests to your local server, which might be as easy as using cURL or other tools like Postman.
Unfortunately my personal experience with PHP tools is limited, so I can't necessarily walk-through the specifics. But it does seem like you know these tools a bit more and should be familiar enough to be able to get started.

About server hosting, and how servers are set up

I have been making a game with javascript for a while now, and I am doing the websocketing with node.js and socket.io.
So my question is: Once I get a server, how would setting it up work? Would I send the people who own the server my files, and then would they take care of setting it up? Would I be able to access the computer they loaned me and set things up from there? I'm confused about the whole process... first time doing anything like this.

How do I connect this chat program to two computers?

So I have been modifying the chat program found here: http://www.dreamincode.net/forums/topic/259777-a-simple-chat-program-with-clientserver-gui-optional/ and I am at the point where I am ready to use it between twp pc's.
The problem is, I do not know enough about server-client relationships to set it up. Is there anything missing in the code for this to work? I just want to link two laptops to chat with one another. Is there any server softare I need to run or something?
I tried openfire but couldn't figure out how to link it, every port number I tried (listed in the admin page) didn't work. This is my first attempt at anything like this and probably beyond my current level of understanding which is why I would greatly appreciate a straightforward solution.
I chose this becaue I needed to do a lot of customization to the code so please use the ones on the page above as a reference. I would post the code here but there are 5 classes and they are neatly displayed on that page already with a explanation of each.
Thanks in advance!
Before you start trying to incorporate external libraries or functions, understand the code. Play around with it a little. See what does what and if you change this setting or that what will happen. Bare in mind that the code is separated into 2 applications:
Client - [ClientUI + Client + ChatMessage]
Server - [ServerUI + Server + ChatMessage]
Check that the application works on a single machine. So keep the server class the same and simply edit the client class so that it points to the current machine.
Run both the server and the client (from the example) on the same machine and when the client asks for the server location input 127.0.0.1 then put the port number you gave for the ServerSocket in Server. This should point to your machine and if this works but not when using 2 separate machines check your firewall settings.

Move files on network to different locations via iPhone app

I have files and directories setup on a Windows network share (\foo). I want to be able to move the files into different directories (eg. \foo\bar\baz.txt --> \foo\quux\baz.txt) via an iPhone app.
However, having failed to find a solution I think it might be a better idea to write a separate program that runs on the server that handles moving the files and have the iPhone app as a client that issues instructions to the server about what files to move.
Any suggestions on this would be much appreciated.
Edit: Since someone has voted to close this for not being clear... the question is: I want to move files on a network share from one directory to the other.
How do I do this using Objective-C/Cocoa Touch/iPhone SDK?
To access the file shares directly, you would have to implement an SMB client. I suppose you could pilfer code from Samba's smbclient and see if you can get it building on the iPhone.
A big advantage to using a web service is that you can set it up for access outside your LAN. This is much harder with SMB unless you already have a VPN set up.
An in-between possibility that just occurred to me is to expose the shares via WebDAV on IIS. In fact, this is probably much easier that writing your own service.