G'day all, I'm new to TCP socket connections (although I build UDP apps fine), and I'm having some trouble creating a very simple TCP socket connection with the Synapse TTCPBlockSocket objects.
The application design is to sit and listen for incoming connections, then when it gets a connection, I need to be able to receive a login string, which is parsed, and if it's valid, I want to create a valid TCP connection with that system, using TCPBlockSocket components. Then the main code's listener goes back to listening for new connection attempts, while the newly created TCPBlockSocket handles the connection to the remote system. But I can't seem to get that (apparently quite basic and simple) part working. In the main form code's OnCreate handler, I create a "master" TCPBlockSocket, bind it to the "any" IP and my listening port number, and call Listen. Then in the main code, on a timer event, I check for readability (CanRead(timeout)), and if it's readable, I try to create a TCPBlockSocket for that connection so I can read the login string and send a response and so on, while the master socket goes back to listening. In the documentation, it states that the Accept method returns a socket reference (I assume it's a socket and not a TCPBlockSocket because that _definitely_ doesn't work!). But on this system, the TCPBlockSocket.Accept method returns a 32-bit signed integer, and I can't seem to get the compiler to allow me cast that to a handle or socket reference (using either Delphi 6 or Turbo Delphi, which I'm locked to as development tools). So I've tried instantiating a new TCPBlockSOcket object when the master socket becomes readable and fill THAT with all the properties of the remote IP, port, and so on from the master socket's connection details, but then that has to be manually connected to the remote system, and that just doesn't work - it never connects. So I'm misunderstanding something very, very basic and simple, and I would appreciate any help understanding where I'm going wrong. I figure it's probably because I can't use a single socket component to listen AND spawn another socket instance for that connection, I should probably run the listener in a thread and notify the main app to spawn a new listener when I get a connection attempt. And I'm not sure if I should be using the master socket to listen and spawn, or listen and connect and the main app spawns a new master listener, etc. I probably need a UDP listener which notifies the main app that an incoming connection request was received, then that spawns a thread with a TCPBlockSocket that then connects with the remote system and validates the credentials (just using simple strings at the moment). But that seems really clumsy, and I'd prefer to use a single TCP connection component without having to do all the pre- and post-connection handling with different components. I know I'm probably wrong, but I don't know where! It seems a bit clumsy to me when I'm used to working with OnReceive type asynchronous UDP events, so if anyone can point me in the right direction to getting this basic stuff working, I'd very much appreciate the help! I'm not looking for a "free lunch", if anyone can point me in the right direction, that would be a great help. Cheers, PCPete ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ synalist-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/synalist-public
