-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I can not found Broadcast message to a connectionId #1
Comments
Hello @majidbigdeli, First of all I am very glad that you are posting questions while this library is still (on the final steps of) work-in-progress! Secondly, you can already achieve this by connecting the connection to a room with the connection's ID as the room name, this way you can use the It's easy to do something like this, we just have to add a At the other hand, the As you probably already know from the Go and JavaScript examples, However, we can have an optional Sounds good to you? |
It's done @majidbigdeli, just fill the server.Broadcast(c, Message{ To: "other connecton id", Namespace: "...", Room: "...", Body: ....}) I decided to not expose the |
…ested at: #1 keep note that namespaces and rooms can send to a group of conns but 1-1 too
Hello my friend @kataras . Finally, I think you made the right decision. @kataras Thanks for implementing Message.To. ❤️❤️ @kataras Thanks for implementing neffos and neffos.js . ❤️❤️ |
This post of yours, my friend @majidbigdeli, is one of the most inspirational messages I have ever received for my work, I am really thankful! Yes, I had a lot of issues working with socket.io at my past career as well. I think a library based on raw websockets is the best option nowdays, note that socket.io has a lot of steps to decide what subprotocol to use for communication(this is the top reason makes that uncompatible with nodejs |
Hi @kataras, may I know the estimated date where this project will be fully integrated and stable with the Iris framework? Sorry to sound demanding but really looking forward to use this together with the Iris framework. Thank you!! |
Hello @lauretagabriel, I feel you, it's a good question. Expect it until the end of the next week, maybe a bit sooner. |
@lauretagabriel @majidbigdeli can I ask you to give some time in order to read and give me feedback about the new neffos wiki Getting Started page, is it understable enough for newcomers and for you? Generally offer some feedback on how to process with it if you want, I want to minimize the README and push a complete guide inside the project's wiki which can be converted to a special book on the future as well. Thank you a lot guys. |
@majidbigdeli Thanks a lot! About JMeter, we can use JMeter with neffos only with the I'll add a wiki page about native messages, although Iris v11.2 has its own example already, but it looks like this: Also note that we have a stress-test for neffos specifically, it's located at: https://github.com/kataras/neffos/tree/master/_examples/stress-test |
Thanks for your nice words and the greek translation too!!! I really appreciate it!!! I am so lucky having you around too! I answered you at the neffos.js project: kataras/neffos.js#2 (comment) |
…et a custom ID Generator as requested at: #1 (comment)
Hey @majidbigdeli, I don't want to depend on Iris for the neffos package because it will make its download heavier, instead I added this feature on the Iris side itself. Using the import "github.com/kataras/iris/websocket"
[...]
irisIDGenerator := func(ctx iris.Context) string {
return ctx.GetHeader("X-Username")
}
app.Get("/my_endpoint", websocket.Handler(websocketNeffosServer, irisIDGenerator)) Wiki: https://github.com/kataras/neffos/wiki/Getting-started#run-the-server |
Thank YOU @majidbigdeli, you are free to give me feedback about the wikis as well or if you found any spelling/language mistakes that I missed please let me know, meanwhile the iris documentation will be centralized to its wiki pages as well. |
@kataras |
@majidbigdeli Both server and client connections shares the same methods, for Why did you expect the server to have an method 1 // [server := neffos.New(..., events)]
server.OnConnect = func(c *neffos.Conn) error {
nsConn := c.Connect(ctx, "namespace") // to force-connect a client connection to a namespace.
// or let the client connect and use
// nsConn := c.WaitConnect(ctx, "namespace") to wait for it.
response, err := nsConn.Ask(ctx, neffos.Message{...})
}
method 2 var events = neffos.Events {
// if you want to wait for a message at the namespace connected.
neffos.OnNamespaceConnected: func(c *neffos.NSConn, msg neffos.Message) error {
response, err := c.Ask(ctx, neffos.Message{...Event:"an event from which response will come"})
},
// if you want to wait for a message inside an event.
"myEvent": func(c *neffos.NSConn, msg neffos.Message) error {
response, err := c.Ask(ctx, neffos.Message{...Event: "otherClientEventOrTheSame"})
},
} |
So you want to send something from a http request to a known upgraded websocket connection and block until response, you may want to check out the Server.Do method, example: server.Do(func(c *neffos.Conn){
if c.ID() == extensionMessage {
response, err := c.Ask(ctx, neffos.Message{...})
// [...]
}
}, false) Aboutthe server.OnConnect = func(c *neffos.Conn) error {
nsConn := c.Connect(ctx, "namespace") // to force-connect a client connection to a namespace.
// or let the client connect and use
// nsConn := c.WaitConnect(ctx, "namespace") to wait for it.
response, err := nsConn.Ask(ctx, neffos.Message{...})
} |
@majidbigdeli Thanks!!! Let's wait for a review then. Also, I think you will find interesting the latest feature I've pushed as requested on #3 |
Yes,
func(c *Conn) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request){
c.Ask...
}
} But to be honest, in your case I would change a different pattern, the problem is that you should not be in this path at the first place, maybe I can provide you a different approach if you could explain me the infostructure. Yes I didn't expect to add a feature like this on the zero version as well, many websocket frameworks don't even have it and they are 4+ years old. I am coding a nats exchange too now, which has also a lightweight client library. |
I really excuse me. My English is not so good . I have cron that run every 1 second
And NotificationHandler()
Attention { Extension Number == Connection Id } I need to get a list of notifications with status = start from the database every 1 second The problem is That if cron run again before update notification status ,a notification send again to user. Because i use Server.Broadcast I can not wait for response so cron run again
for solution 1 neffos have
i can use |
@majidbigdeli I've just pushed a |
@kataras . |
@kataras
Because the server is blocked it is not good . because it call every 1s. |
You don't need this @majidbigdeli, |
thank you |
Move your whole logic PER CONN inside the server.OnConnect = func(c * neffos.Conn) error {
// a function that is a wrapper of your cron and contains
// a field with the connection to work with.
cronJob := getCronJobForConnection(c)
c.Set("cron", cronJob)
// the OnDisconnect below will call its cronJob.Stop but for any case
// ... inside your cronJob.Start method check for MyCronType.Conn.IsClosed() -
// if it's closed then exit from go routine.
go cronJob.Start()
return nil
}
server.OnDisconnect = func(c *neffos.Conn) {
if v := c.Get("cron"); v != nil {
// optional type check or v.(MyCronType).Stop()
if cronJob, ok := v.(MyCronType);ok {
job.Stop()
}
}
} UPDATE |
@kataras |
OK nice @majidbigdeli, check my updated answer above and tell me if that helped you with the cron thing, otherwise I will push an example :P So it's time to think a way to make this |
Do you suggest that for each connection makes a cron job ? please see https://github.com/majidbigdeli/neffosAmiClient i send list of connectionId(extentionNumber) to database and i get list of notification Updatemy database is sql server and I send list of connectionId with Tvp to database |
yes . Thank you if you push an example. |
No, I suggested to return a wrapper for this but now I see the whole code you use, and I understand some things, please answer the above so I can provide more help:
So that you need is a My recommendation is very simple and efficient: We could add a In that Sounds good? EDIT : However, such a feature like this couldn't be ever compatible with StackExchange across different neffos instances because of the func. So I have to ask you two more things:
Server.Broadcast(nil, neffos.Message{
// this is the namespace that should be force-connected on `Server.OnConnect`.
Namespace: variable.Agent,
Event: variable.OnNotification,
Body: neffos.Marshal(element),
}) With above you could easly call server.Broadcast and it would sent to the subcollections as you want without blocks and with scaling-out option available. |
I just need a List connection Id.
|
Thank you for this |
As I already mentioned neffos does not keep a collection like this because by-default there is no guarante that an ID is mapping only to one single connection and for other performance reasons. I am preparing an example for you, it will take some time because I do 1000 things in the same time:p UPDATE I tried to follow the logic of your application and pushed an example at: https://github.com/kataras/neffos/blob/master/_examples/cronjob/main.go - that example shows various things that may help you in general, please tell me if that helped. |
… can be done very easly but it's based on a problem described at: #1 (comment)
@majidbigdeli |
@kataras . I do not have any brother but you are like a brother Thank You. I can not use neffos.message Without To Because websocket connection id 1 have ( message id 1 , messageId 2 ,messageId 3) and websocket connection id 2 have (messageId 4 , messageId 5) and websocket connection id 3 have (messageId 6 , messageId 8, messageId 12,) . user with websocket connection Id 1 should not see messageId 5 . I get all messages for all online users with send list websocket connection Id to database. I do not intend to send all the messages to all online users. Each user must receive their messages. I need list websocket connection Id without server block . your example is very good.. |
Thanks @majidbigdeli I will try to not let you down then!! I am very honored. So that's exactly the example does, we will let it there, and if you want you can improve it, for other users that may have the same application requirements as yours, sounds good? |
@kataras Thank You . |
@kataras |
You have right @majidbigdeli , this happens because the parsing of url params as headers (for browser side header settings) it's done after the Iris' id generator call. Fixed now, it will be pushed on the Iris v11.2.3 and the neffos 0.0.9 version (I made a change here too which fixes this issue and other issue that an Iris ID generator was called before the handshake, which logically is wrong). |
…quested at: kataras/neffos#1 (comment) Former-commit-id: 0994b63373ebe2b5383a28f042aa2133061cbd18
…/neffos#1 (comment) Former-commit-id: 9753e3e45c7c24788b97814d3ecfb4b03f5ff414
How Sending message to specific user with neffos ?
I can not found Broadcast message to a connectionId
The text was updated successfully, but these errors were encountered: