PDA

View Full Version : server sockets


venkat786
06-17-2003, 03:43 AM
Hi,
I am presently using server sockets introduced in v2.1.
my doubts are

1.what function from the client side causes an event to be raised on the server socket which is in listening mode?

2. When to call the Accept function on the server side?
Actually BREW api 2.1 says that an event EVT_NET_READ............
will be raised. But when i am using this in my program i am getting syntax error.

please help me...

kurquhar
06-17-2003, 04:09 PM
Answers:
1. a connect from the client side causes the listening server socket to become readable
2. Use ISOCKET_Readable() to schedule a callback, in which you can call ISOCKET_Accept() to get the new connection (but be prepared for AEE_NET_WOULDBLOCK again). I agree that the documentation is confusing.

venkat786
06-24-2003, 03:04 AM
I am unable to understand what API 2.1 is explaining about the usage of server sockets

1) I want to know whether anybody is able to use bind,listen and accept functions successfully?

2) How to write a bind function for server socket and is it compulsory?

3)when to call listen function?

4) can we run both client and server from a single BREW applet?

Can any one pass sample code if it is running sucessfully?

kurquhar
06-24-2003, 10:16 AM
1) yes, in the SDK and on devices with MSM 6100 or later chipsets. If you are trying this on a device with an older chipset, server socket operations will return AEE_NET_EOPNOTSUPP.
2) using bind is not compulsory, but it sure makes it easier for the client to know what port to connect to ;) If you do not explicitly bind, BREW will bind for you to a port of its choosing. Use HTONL(AEE_INADDR_ANY) for the address, and HTONS(port) for whatever port you would like to use.
3) right after bind
4) yes, you can use either HTONL(AEE_INADDR_LOOPBACK) or HTONL(AEE_BREW_LOOPBACK) for the address during connect.

One thing you may have missed in the release notes is that you need to hand edit the skin file to enable server sockets in the 2.1 SDK. I have attached the skin file that I use for your reference.

BREW server sockets are modeled after BSD sockets, with the exception that they are non-blocking. See e.g. Stevens, "UNIX Network Programming Volume 1", for more detailed explanantions of client/server socket programming principles.