[gnet] Gnet-2.0.7 and win32



Title: Gnet-2.0.7 and win32

Dear gnet list,

I'm trying to use libgnet-2.0.7 (and GTK+-2.4) for a GUI program.
Without going into too much detail, the GUI basically opens a TCP
connection to a server and starts reading and writing ascii-text
lines to/from it.

This works good when the GUI client runs on Linux, but on win32
I run into problems..


While testing I just use netcat for the server like this:

 nc -l -p 1234

First I looked into the echoclient example programs and they all
works good in Linux, but when compiling them on win32 (with MinGW)
I'm having various problems.

Browsing the gnet list I see that there seems to be problems with
iochannels and glib on win32. The echoclient that is closest to working
is echoclient-async.c.

On Linux all strings typed in the echoclient-async window directly shows up
in the netcat window and vice versa. But on Win32 (Windows XP service pack 1)
only lines that are typed in the echoclient-async window are directly sent.
Lines typed in the netcat window seems to buffer up somewhere. When I break the
connection by typing Ctrl-C in the netcat window then all lines that
was previously typed in the netcat window show up in the echoclient-async
window. I tried running the netcat command on both Linux and Windows and
the result is the same.

I modified the code to use only one io watch to try to isolate the problem.
In the async_client_connfunc callback I just have:

 iochannel = gnet_tcp_socket_get_io_channel(socket);
 g_io_add_watch(iochannel, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
                async_client_iofunc, NULL);

But async_client_iofunc dont get called until the connection is hanged up
by typing Ctrl-C in the netcat "server" window.

Then, just for test, I tried to "manually" read and write lines by inserting
this directly after the g_io_add_watch line:

 gnet_io_channel_readline_strdup(iochannel, &str, &n);
 if (str != NULL) {
    g_print("read line: %s\n", str);
    g_free(str);
 }

 gnet_io_channel_writen(iochannel, "Hello, netcat!\n", 15, &n);


And this works on both Linux and Windows. After the first line is sent from netcat
then the client responds with "Hello, netcat!". But then no more lines are received
from netcat until the connection is killed...

I built gnet-2.0.7 under MinGW (MinGW-3.2.0-rc3, MSYS-1.0.10 and msysDTK-1.0.1) with just

 ./configure

Should there be some extra arguments to configure when building on win32?

By the way, the glib version I use is 2.4.7 and it is taken from
Tor Lillqvists gimp page: http://www.gimp.org/~tml/gimp/win32/.
I did not try with glib-2.6.

More questions. Is it possible to work around the io_channel problem in some way?
I am thinking about spawning a new thread that calls gnet_io_channel_readline_strdup()
in a loop to receive lines and use gnet_io_channel_writen() to send lines from the
"main" thread. If I do it this way, is it safe. Would it work if, for example, a line is
received exactly at the same time as I try to send a line from the main thread.


Hope someone has the time to answer my questions.

Regards, Albert



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]