Skip to content

add TCP and UDP server samples - #243

Merged
psychon merged 2 commits into
lgi-devs:masterfrom
matsievskiysv:master
Apr 9, 2020
Merged

add TCP and UDP server samples#243
psychon merged 2 commits into
lgi-devs:masterfrom
matsievskiysv:master

Conversation

@matsievskiysv

Copy link
Copy Markdown

Add TCP and UDP server samples.
See #235 for details.

Comment thread samples/udpsrv.lua Outdated

@psychon psychon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the examples and sorry for the many comments

Comment thread samples/tcpsrv.lua Outdated
Comment thread samples/tcpsrv.lua Outdated
Comment thread samples/tcpsrv.lua Outdated
Comment thread samples/tcpsrv.lua Outdated
Comment thread samples/tcpsrv.lua Outdated
Comment thread samples/tcpsrv.lua Outdated
Comment thread samples/tcpsrv.lua
local Gio = lgi.Gio

local app = Gio.Application{application_id = 'org.test.tcptest',
flags = Gio.ApplicationFlags.NON_UNIQUE}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a Gio.Application? I have to admit, I do not really know what this is doing, but I would just remove the app.
(Especially with the NON_UNIQUE argument... what does Gio.Application do?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly everything should be using Gio.Application, manually dealing with the mainloop isn't helpful.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, what does GApplication do that GLib.MainLoop.new():run() does not do? I really have no idea.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most examples use Gio.Application. Probably because syntax is the same as for Gtk.Application.

@TingPing TingPing Apr 9, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of a demo, nothing. In real world applications, single instance support, daemonization, argument parsing, gresource loading, global menus, exporting the freedesktop application dbus interface, its just the API applications should use.

Comment thread samples/udpsrv.lua
Comment thread samples/udpsrv.lua Outdated
Comment thread samples/udpsrv.lua Outdated
@matsievskiysv

Copy link
Copy Markdown
Author

Copied assertion from samples/giostream.lua, so it should be double checked. Applied other suggestions.

@matsievskiysv

Copy link
Copy Markdown
Author

Tried to test error handling by inserting packet delays and errors via tc, but it didn't work. I think, these errors were caught on kernel level. How do I get Gio to fail?

@psychon

psychon commented Apr 9, 2020

Copy link
Copy Markdown
Collaborator

I don't know why, but the TCP echo server truncates(?) long messages. I used copy&paste to generate lots of "o"s, but the server answered with less "o"s.

I tried to get some kind of error, but I also failed. I guess just guessing that it works should be okay then.

@TingPing You already checked an earlier version of this. Any more comments or should I just merge this?

@TingPing

TingPing commented Apr 9, 2020

Copy link
Copy Markdown
Contributor

Seems good.

@matsievskiysv

Copy link
Copy Markdown
Author

I don't know why, but the TCP echo server truncates(?) long messages. I used copy&paste to generate lots of "o"s, but the server answered with less "o"s.

This may be a netcat issue. I used this sample text. When I copy/pasted it into ncat, it got truncated on the phrase From whispers in the wind he could foretell the next day’s weather. Bec, but when I piped xclip contents to the ncat, server received the whole text.

@psychon
psychon merged commit 9541863 into lgi-devs:master Apr 9, 2020
@psychon

psychon commented Apr 9, 2020

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants