Hi,
I'd like to establish connection between my application and a remote server. Ideally it would be using webSocket since the communication is bi-directional and asynchronous.
However, In case the webSocket isn't established properly or failing sometime after it was created (due to firewall, proxy servers, network switching or any other reason), than I'd like to switch to using periodical simple HTTPS POST requests (keep alive messages) where the server-to-client data transferred on the responses. The server should also support both communication methods.
The following code should reflect my approach. Please advise if this could work or perhaps there are built-in solutions in the framework.
NSURL * reqUrl = [NSURL URLWithString:@"wss://mydomain.com"];
NSURLSession* session = [NSURLSession sessionWithConfiguration:
[NSURLSessionConfiguration defaultSessionConfiguration]];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:reqUrl];
webSocketTaskWithURL * socketConnection = [URLSession webSocketTaskWithURL:url];
socketConnection.resume()
[socketConnection sendMessage:message completionHandler: ^(NSError * e) {
if (e != nil) {
// fallback to https
[req setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]]
NSURLSessionDataTask *data_task_http = [session dataTaskWithRequest:req];
completionHandler:
^(NSData * _Nullable data,
NSURLResponse * _Nullable
response,
NSError * _Nullable error) { /*blabla*/}];
[data_task resume];
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I've got the following code that I use to communicate with a remote server. However, when the response contain a large enough file, the callback block never called, the only thing that trigger the callback, is when I explicitly invoke the cancel method after some timeout from the NSURLSession task (_dataTask).
notice that using tcpdump I did observe that the response was properly received on the client side.
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 1;
NSURLSession* session = [NSURLSession sessionWithConfiguration:config delegate:nil delegateQueue:queue];
_dataTask = [session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if ([error code] == NSURLErrorCancelled) {
writeLog(LOG_ERROR, "NSURLErrorCancelled");
} else {
<my completion callback>
}
}];
[_dataTask resume]
I'd like to know if using dataTask has response size limit (because it's working for small files on response body)
and if there is such a limit, so which other method should I use in order to overcome it. I saw that there's an alternative method in NSUrlsession dedicated for downloading files called downloadTaskWithRequest but it doesn't have an async completion block.
Hi,
I've set the C++ language dialect in my project to c++2a.
Than it failed on compiling .mm file which has the following line
@import AppKit;
But if replace it with the following line and link with framework from project build phases, than it works.
#import <AppKit/AppKit.h>
My .mm file is including for adapter swift header file (*-Swift.h) which is auto generated and has this @import directive.
is it a known issue, should I file a bug ?
I'd like to add a short script that runs clang-format upon trying to save a file in Xcode project.
the script will do the following command :
#!/bin/zsh
/usr/local/bin/clang-format -i <saved_file>
Does Xcode support this feature (in visual studio it's called
format-on-save :
https://code.visualstudio.com/updates/v1_6#_format-on-save
Hi, I was wondering if there's any option to run xcodebuild to compile the project and skip the code signing phase, even though, a signing account is set in the project under signing and capabilities.
The motivation for that, is that on some occasions, my project get built using GitLab CI/CD pipeline, which have machine pool that doesn't have Xcode with account. So I'd like to build only and check that nothing got broken.
thanks
Hi,
I've made a pkg installation file that usually works. However, for some setups I gets the following failure after postinstall finish (return 0)
2023-01-12 10:52:00-08 ESXBigSurVM-5 package_script_service[815]: Responsibility set back to self.
2023-01-12 10:52:00-08 ESXBigSurVM-5 installd[781]: PackageKit: Writing receipt for com.myprod.mycomp to /
2023-01-12 10:52:00-08 ESXBigSurVM-5 install_monitor[814]: Re-included: /Applications, /Library, /System, /bin, /private, /sbin, /usr
2023-01-12 10:52:01-08 ESXBigSurVM-5 installd[781]: PackageKit: releasing backupd
2023-01-12 10:52:01-08 ESXBigSurVM-5 installd[781]: PackageKit: allow user idle system sleep
2023-01-12 10:52:01-08 ESXBigSurVM-5 installd[781]: PackageKit: Cleared responsibility for install from 773.
2023-01-12 10:52:01-08 ESXBigSurVM-5 installd[781]: PackageKit: Cleared permissions on Installer.app
2023-01-12 10:52:01-08 ESXBigSurVM-5 installd[781]: PackageKit: Install Failed: Error Domain=NSCocoaErrorDomain Code=513 "You don't have permission to save the file "com.myprod.mycomp.bom" in the folder "receipts"." UserInfo={NSFilePath=/var/db/receipts/com.myprod.mycomp.bom, NSUnderlyingError=0x7f92fe515760 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} {
NSFilePath = "/var/db/receipts/com.myprod.mycomp.bom";
NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=1 \"Operation not permitted\"";
}
2023-01-12 10:52:01-08 ESXBigSurVM-5 installd[781]: PackageKit: Running idle tasks
I've used the installer command with sudo, but i'm still getting the permissions issue ...
sudo /usr/sbin/installer -pkg /path/to/my/file.pkg -target /
Any idea why this is happening only in some setups (usually VMs running BigSur) ? and how could i prevent it ?
I'm looking for API to add a new kerberos credentials to macOS internal ticket store.
Basically, I'd like to replace the whole authentication process with a proprietary component and not rely on the OS kerberos implementation, and get the following items:
Client-to-server ticket encrypted using the resource's secret key.
A new Authenticator encrypted using Client/Server Session Key
I'd like to set these 2 items where the OS keeps these items to be used when communicating with the resource itself.
Also, I'd like to keep another kerberos item retrieved after the first communication with the resource and it's used for SSO to allow additional request to the resource for a certain period of time. this item is the timestamp found in client's Authenticator encrypted using the Client/Server Session Key
Is there an API I can use to inject those items to where the OS keeps the kerberos Items so it can use them when it access the resource itself.
Hi,
I am using xcode build that receive it's configuration using xcconfig files, those add some new definitions to the project, like the location of openssl library.
If xcode environment variable include prefix that matches one of the fields in the project settings, it is automatically referred to as if you added it to that field.
for example : the var HEADER_SEARCH_PATHS_openssl_libopenssl has value (openssl headers' path) that should be automatically added to the field Headers Search Paths under project settings.
For some reason it stopped working for me and i'm not sure why (i've tried to release the xcconfig files). any idea why ?
Thanks !
Hi,
I've created persistent task from type launchDaemon based on bash script that should run one time upon first load.
These are the contents of the plist file :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.blabla.task</string>
<key>RunAtLoad</key>
<true/>
<key>LaunchOnlyOnce</key>
<true/>
<key>Program</key>
<string>/Library/Application\ Support/myComp /script.sh</string>
</dict>
</plist>
However, when i load the plist using launchCtl, nothing happens and no meaningful log appears...
However, when the Program location changes to /tmp/script.sh then everything is working great
So i conclude that there's permission issue to access Library/Application\ Support, although the file permission is allow for all -rwxrwxrwx.
But when I give back full disk access in privacy setting, it's working from the /Library.. path.
My question is why does bash launchd task that runs with privileges, also requires this privacy acknowledge in order to run the script?
Hi, I'm looking for a way to integrate clang-tidy rules with my xcode project. is there a way xcode can read .clang-tidy files and add the rules to each compilation line ?
I couldn't find anyway to do it, so i presume it's unsupported. but perhaps there can be some workaround i can use to modify the compilation according to clang-tidy rules that the IDE read from a file.
thanks !
I'd like to get an indication about the context in which my process is running from. I'd like to distinguish between the following cases :
It runs as a persistent scheduled task (launchDaemon/launchAgent)
It was called on-demand and created by launchd
using open command-line or double-click.
It was called directly from command-line terminal (i.e. > /bin/myProg from terminal )
Perhaps is there any indication about the process context using Objective-c/swift framework or any other way ?
I wish to avoid inventing the wheel here :-)
thanks
Topic:
App & System Services
SubTopic:
Core OS
Tags:
macOS
Swift Packages
Objective-C
Inter-process communication
Consider a C++ method that retrieve struct of native typed arguments like enum class, sub-structs, std::string, int, etc...
I'd like to create a swift API that return the same struct but in swift variables
for example :
class ErrorMessage {
public:
int status;
std::string message;
};
class serverResponse {
public:
ErrorMessage error;
std::string str_value;
std::uint16_t int_val;
std::time_t last_seen;
EnumVal status;
};
serverResponse getServerResponse();
So I'd like to convert it to the swift equivalent struct with native members
open class serverResponseSwift : NSObject {
open class var error: ErrorMessage { get }
open var str_value: String { get }
open var int_val: UInt16 { get }
open var status: EnumVal { get }
};
I know that direct conversion is not yet possible so I need to use objective-C++ code as a mediator. So I've used a bridging header to include the converting method in objective-C++ which will look like this :
@interface Converter
- (serverResponseSwift) getServerStatusSwift;
@end
and the equivalent .mm file will implement the conversion function, but can I use the swift Class in objective-c in order to fill it up according to the CPP serverResponse ?
@implementation Converter
- (serverResponseSwift) getServerStatusSwift {
serverResponse x = getServerResponse();
/// How do I create serverResponseSwift out of serverResponse
}
Thanks !
Hi, I was wondering if there's any limitation for the context where I initialize my xpc service.
This is the code that initialize my xpc service :
listener_ = [[NSXPCListener alloc]
initWithMachServiceName:@"com.bla.bla"];
xpcService *delegate = [xpcService new];
listener_.delegate = delegate;
[listener_ resume];
[[NSRunLoop mainRunLoop] run];
Doing it from the main method and everything works just fine. However, when calling it from different method(main)/thread(main thread)... It doesn't accept remote calls although it seems like the listener was properly initialized.
I even tried to wrap this code to run on the main thread using the following wrapper
dispatch_sync(dispatch_get_main_queue(), ^{
listener_ = [[NSXPCListener alloc]
initWithMachServiceName:@"com.bla.bla"];
xpcService *delegate = [xpcService new];
listener_.delegate = delegate;
[listener_ resume];
}
where the [[NSRunLoop mainRunLoop] run]; is called from the main method...
So my question is what are the requirements to make the XPC work.. is it mandatory to call it from the main method ?
Hi,
I'm using the reachability framework in order to register network status event for a specific address (address_st in the code below)...
I'd like to support change of address which will trigger unregister from the old address and register to the new one. How can it be done ?
SCNetworkReachabilityRef reachabilityRef =
SCNetworkReachabilityCreateWithAddress(NULL, reinterpret_cast<sockaddr *>(&address_st));
SCNetworkReachabilityContext context = {0, NULL, NULL, NULL, NULL};
SCNetworkReachabilitySetCallback(reachabilityRef, ReachabilityCallback, &context))
SCNetworkReachabilitySetDispatchQueue(reachabilityRef,
dispatch_queue_create("com.reachability.test", nil));
thanks,
Hi, I've like to calculate the path mtu between one of the local interfaces and a remote address.
Perhaps there's such option using native networking framework like nsurlconnection ?
Should I need to set the DF (don't fragment) bit and send to each hop in the path, or can I acquire this value from some cached storage per connection ?
thanks