Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Non Blocking Client/Server Sockets, SocketError 10035

812 views
Skip to first unread message

Mokwaja

unread,
Mar 26, 2004, 6:27:34 AM3/26/04
to
Hi,

When modifying the D7 NetChat application- setting the both TTCPServer and TTCPClient to non-blocking causes the OnAccept (or all events?) not to fire. How do you use OnAccept for example with a non-blocking TTCPServer?

I'm not writing a chat app, I just used this for an example.

-------------------------------------------- Question Mod-------------------
Ok based on my question above, I created 2 new projects, and I found that the ClientSocket never connected thus the TCPServer.OnAccept didn't fire... This is what I'm doing now:

1. On Project1 (Server) I have a TTCPServer set with the following props:
'LocalPort' = '8888'
'BlockMode' = 'bmNonBlocking'

on The FormCreate event I set the TCPServer to active

2. On Project2 (Client) have a TTCPClient set with the following props:
'RemotePort' = '8888'
'RemoteHost' = set to local machine/network IP
'BlockMode' = bmNonBlocking
'OnError' handler

In a button's click event I do the following:

....
Try
TCPClient.Active := True; //Question A
Except
On E: Exception Do
Begin
Memo.Lines.Add(E.Message);
End;
End;

If TCPClient.Connect Then //Question B
TCPClient.Sendln(Edit1.Text);

....
In the TCPClient.OnError Event:
ShowMessage('Error: ' + IntToStr(SocketError));

A.) When I run the client app(with the Server app already running) and click the button, error 10035 gets caught in the 'OnError' event. I looked the error up and it means:

"Socket error (#10035): Resource temporarily unavailable.
This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established"

Any idea why this happens?

B.) When the line "If TCPClient.Connect Then" executes, OnError handler catches SockError 10022 which is:

"WSAEINVAL 10022
Invalid argument.
Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt function). In some instances, it also refers to the current state of the socket庸or instance, calling accept on a socket that is not listening. "

Which I think happens cause of the TCPClient.Active that caused SockError 10035 and didn't complete properly (Although if you check TCPServer.Active it returns True after Error 10035 occurred)

Any ideas or suggestions welcome.

Mokwaja.

Remy Lebeau (TeamB)

unread,
Mar 26, 2004, 2:49:49 PM3/26/04
to
"Mokwaja" <mok...@yahoo.com> wrote in message
news:406413a6$1...@newsgroups.borland.com...

> When modifying the D7 NetChat application- setting the
> both TTCPServer and TTCPClient to non-blocking causes
> the OnAccept (or all events?) not to fire. How do you use
> OnAccept for example with a non-blocking TTCPServer?

OnAccept is only triggered when Accept() is called. Accept() is not called
automatically in non-blocking mode. Accept() is only called automatically
when blocking mode is used, thus TTCPServer creates a thread internally that
calls Accept() over and over in a loop. Since you are using non-blocking
instead, the thread is not created, thus Accept() is not called
automatically, and as such you have to call it yourself manually
periodically.

I do not recommend you use TTCPClient/Server in general. They are poorly
designed. Use TClientSocket/Server instead, or if you need cross-platform
support then use Indy (http://www.indyproject.org) or ICS
(http://www.overbyte.be) instead.


Gambit


0 new messages