我得到了一个用Laravel 4编写的web应用程序.这个应用程序使用了Ratchet,更具体地说,它使用了Latchet软件包.作为旁注,我使用以下技术:
现在我得到以下场景:
在我的routes.php中,我有以下代码,以便正确注册主题:
//routes.php
// Setup a connection and register a topic where clients can connect to.
Latchet::connection('Connection');
Latchet::topic('PhotoStream/{client}', 'PhotoStreamController');
Run Code Online (Sandbox Code Playgroud)然后,我启动棘轮服务器.
sudo php artisan latchet:listen
当照片上传后,我可以运行以下代码将更新推送到正在收听我主题的客户端(PhotoStream/client1在本例中):
// Create the object, save it to db and then publish it to my websockets
$photo = new Photo;
$photo->location = 'path/to/file';
$photo->save();
// Publish it through my websocket clients. (push from server).
Latchet::publish('PhotoStream/client1', array('msg' => $photo->toArray() ));
Run Code Online (Sandbox Code Playgroud)
这段代码都有效,但是在更新的情况下.我的问题如下:
我该如何处理客户端的初始化?
这两个选项中的后一个对我来说似乎是最好的选择,但我真的不知道如何以一种好的方式实现它.
如何使用IntStream在步骤(3)中迭代一系列数字(0-100)?
我试过iterate,但这永远不会停止执行.
IntStream.iterate(0, n -> n + 3).filter(x -> x > 0 && x < 100).forEach(System.out::println)
Run Code Online (Sandbox Code Playgroud) 使用Akka-HTTP绑定对端口9000的调用时
Http().bindAndHandle(routes, "localhost", 9000)
Run Code Online (Sandbox Code Playgroud)
它开始监听端口,如'netstat -tulpn'所示
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp6 0 0 127.0.0.1:9000 :::* LISTEN
Run Code Online (Sandbox Code Playgroud)
本地可以使用此端口.但是,当我拨打远程电话时,我得到:
curl: (7) Failed to connect to 169.254.0.2 port 9000: Connection refused
Run Code Online (Sandbox Code Playgroud)
即使可以进行ping操作,也可以直接连接设备.我究竟做错了什么?
我喜欢 IntelliJ 任务来简化我的工作流程。但是,当我关闭任务并检查 时merge with branche(s),它合并了我的功能分支,没有no-ff.
如何启用no-ffIntelliJ 任务?
基本上:一个方法需要返回一个在dispatch_async中获取的NSDictionary.这是我尝试过的:
- (NSDictionary *)fetchNSDictionary {
dispatch_queue_t Queue = dispatch_queue_create("Dictionary fetcher", NULL);
dispatch_async(Queue, ^{
NSDictionary *dict = ...
dispatch_async(dispatch_get_main_queue(),^{
return dict;
)};
)};
}
Run Code Online (Sandbox Code Playgroud)
结果:
Incompatible block pointer types passing 'NSDictionary *(^)(void)'
to parameter of type 'dispatch_block_t' (aka 'void (^)(void)')
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
如何轮询具有停止轮询直到服务的返回值满足条件或总持续时间超过超时阈值的效果的服务?
例如:后端系统正在生成资源,前端应用程序可以通过调用返回布尔值的 REST api 调用来检查该资源是否可用。在我的 NGRX 应用程序中,我想每 200 毫秒轮询一次此 api 调用,直到此 api 调用返回布尔值 true 或总轮询持续时间超过 10000 毫秒的阈值。
以下代码示例显示了一种轮询机制,但是,该轮询无法取消,也没有超时。这是怎么做的?
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/timer';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
@Effect()
pollEffect$: Observable<Action> = this.actions$
.ofType(tasksActions.ActionTypes.START_POLLING)
.switchMap(() => Observable.timer(0, 200)
.switchMap(() => this.myBackendService.getAvailability().map(response =>
return taskActions.ActionTypes.UpdateValue(response))
)
);
Run Code Online (Sandbox Code Playgroud) 是否可以将方法的引用作为参数传递?
例如:
public static void main(String[] args) {
String data = "name: John, random text, address: leetStreet";
Person person;
//if regex matches, use method reference, to send the result.
applyDataToPerson(data, "name: (\\w+)", person, Person::setName);
applyDataToPerson(data, "address: (\\w+)", person, Person::setAddress);
}
private static void applyDataToPerson(String data, String regex, Person person,
Function<Person> f) {
Matcher match = Pattern.compile(regex).matcher(data);
if (match.matches()) person.f(match.group(1));
}
class Person {
private String name;
private String address;
public void setName(String name) {
this.name = name;
}
public void …Run Code Online (Sandbox Code Playgroud) java ×2
java-8 ×2
akka ×1
akka-http ×1
angular ×1
git ×1
ios ×1
lambda ×1
laravel ×1
laravel-4 ×1
ngrx ×1
ngrx-effects ×1
ngrx-store ×1
objective-c ×1
phpwebsocket ×1
port ×1
ratchet ×1
scala ×1
zeromq ×1