Re: [gnet] A couple of questions about GServer and GConn etc.



Sorry for the delayed reply, I've been out of town.

On 27 Mar 2002, Kent Nyberg wrote:
> I am trying to use GServer and GConn to do some simple communication in
> my testprogram.
>
> In gnet_server_new(...) i have the serverfunction that will
> communicate with the client. Is this the correct way to do it?
>
> I have not that much experience of doing network-programming so i am not
> sure this is the correct way.
>
>
> In my testprogram i also created the client that will connect to my
> server when it is created.
> In gnet_conn_new(..) i have my clientfunction that will communicate with
> the client, is this the correct way?
>
> In my serverfunction i can check the status and get the IP from the
> client so the testprogram workes as it should.

Sounds right.  Check out the echoclient and echoserver examples in the
examples directory.

> The thing is that i am not 100% sure of how to write and read from/to
> the client/server.
>
> Should i just use the 'gnet_conn_write()' and gnet_conn_read()' in the
> serverfunction and the clientfunction?
> The 'gnet_conn_read' function needs a new kind of function in its
> arguments. What is this function doing? Should i use the
> 'gnet_conn_readline()' instead?

The easiest way is to use g_iochannel_read/write() on the iochannel
(conn->iochannel).  This blocks though, which may be bad if your channel
is unthreaded or must interoperate with other clients/servers.
gnet_conn_read/write/readline() are asynchronous versions which call a
callback when complete.  echoserver and echoclient demonstrate these.

> A tutorial on tcp/ip programming i found on the internet i learned that
> usually you need to accept() a connection on a socket, do the
> serverfunction this automatic?

Yes.

David


-- 
      __          _    __ David Helder - dhelder umich edu
  ___/ /__ __  __(_)__/ / <http://www.eecs.umich.edu/~dhelder>
 / _  / _ `/ |/ / / _  /  Jungle Monkey: <http://www.junglemonkey.net>
 |_,_/|_,_/|___/_/|_,_/   Paper CD Case: <http://www.papercdcase.com>




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