2
2
3
3
private Gtk . Button button_connect;
4
4
private Gtk . Button button_disconnect;
5
+ private Gtk . Entry entry_url;
5
6
private Gtk . Button button_send;
6
7
private Soup . WebsocketConnection connection;
7
8
8
9
public void main () {
9
- button_connect = workbench. builder. get_object (" button_connect" ) as Gtk . Button ;
10
- button_disconnect = workbench. builder. get_object (" button_disconnect" ) as Gtk . Button ;
11
- button_send = workbench. builder. get_object (" button_send" ) as Gtk . Button ;
12
- var entry_message = workbench. builder. get_object (" entry_message" ) as Gtk . Entry ;
10
+ entry_url = (Gtk . Entry ) workbench. builder. get_object (" entry_url" );
11
+ button_connect = (Gtk . Button ) workbench. builder. get_object (" button_connect" );
12
+ button_disconnect = (Gtk . Button ) workbench. builder. get_object (" button_disconnect" );
13
+ button_send = (Gtk . Button ) workbench. builder. get_object (" button_send" );
14
+ var entry_message = (Gtk . Entry ) workbench. builder. get_object (" entry_message" );
13
15
14
16
button_connect. clicked. connect (connect. begin);
15
17
@@ -18,16 +20,13 @@ public void main () {
18
20
});
19
21
20
22
button_send. clicked. connect (() = > {
21
- var text = entry_message. get_text ();
22
- send (text);
23
+ send (entry_message. text);
23
24
});
24
25
}
25
26
26
27
private async void connect () {
27
- var entry_url = workbench. builder. get_object (" entry_url" ) as Gtk . Entry ;
28
-
29
28
try {
30
- var uri = GLib . Uri . parse (entry_url. get_text (), GLib . UriFlags . NONE ). to_string ();
29
+ string uri = GLib . Uri . parse (entry_url. text, NONE ). to_string ();
31
30
var session = new Soup .Session ();
32
31
var message = new Soup .Message (" GET" , uri);
33
32
@@ -38,44 +37,46 @@ private async void connect () {
38
37
1 ,
39
38
null );
40
39
} catch (Error err) {
41
- stderr. printf (" error: " + err. message + " \n " );
40
+ stderr. printf (@" Error : $( err.message) \n " );
42
41
return ;
43
42
}
44
43
45
- connection. closed. connect (onClosed );
46
- connection. error. connect (onError );
47
- connection. message. connect (onMessage );
44
+ connection. closed. connect (on_closed );
45
+ connection. error. connect (on_error );
46
+ connection. message. connect (on_message );
48
47
49
- onOpen ();
48
+ on_open ();
50
49
}
51
50
52
- private void onOpen () {
51
+ private void on_open () {
53
52
stdout. printf (" open\n " );
54
- button_connect. set_sensitive ( false ) ;
55
- button_disconnect. set_sensitive ( true ) ;
56
- button_send. set_sensitive ( true ) ;
53
+ button_connect. sensitive = false ;
54
+ button_disconnect. sensitive = true ;
55
+ button_send. sensitive = true ;
57
56
}
58
57
59
- private void onClosed () {
58
+ private void on_closed () {
60
59
stdout. printf (" closed\n " );
61
60
connection = null ;
62
- button_connect. set_sensitive ( true ) ;
63
- button_disconnect. set_sensitive ( false ) ;
64
- button_send. set_sensitive ( false ) ;
61
+ button_connect. sensitive = true ;
62
+ button_disconnect. sensitive = false ;
63
+ button_send. sensitive = false ;
65
64
}
66
65
67
- private void onError (Error err) {
68
- stdout. printf (" error\n " );
69
- stderr. printf (err. message);
66
+ private void on_error (Error err) {
67
+ stderr. printf (@" Error: $(err.message)\n " );
70
68
}
71
69
72
- private void onMessage (int type, Bytes message) {
73
- if (type != Soup . WebsocketDataType . TEXT )return ;
70
+ private void on_message (int type, Bytes message) {
71
+ if (type != Soup . WebsocketDataType . TEXT ) {
72
+ return ;
73
+ }
74
+
74
75
string text = (string ) message. get_data ();
75
- stdout . printf ( " received: " + text + " \n " );
76
+ print ( @" Received: $ text\n" );
76
77
}
77
78
78
79
private void send (string text) {
79
- stdout . printf ( " sent: " + text + " \n " );
80
+ print ( @" Sent: $ text\n" );
80
81
connection. send_text (text);
81
82
}
0 commit comments