[Synalist] Newb help needed with "simple" TCP Connections using TCPBlockSocket

2008-11-28 Thread Audiography (Peter Naus)
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
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public


[Synalist] udp Broadcast problem

2008-11-28 Thread Arthur Hoornweg
Hello all,

I'd like to send an UDP broadcast to "255.255.255.255" using
tudpBlockSocket.

Unfortunately this fails if the computer has more than 1 network
card.

What can I do?



The code I use is this:


Procedure Test;
Var
   Sock  : TUDPBlockSocket;
   s, t,  remoteip: ansistring;
   start, dauer  : dword;
Begin
try
 Sock := TUDPBlockSocket.Create;
 sock.EnableBroadcast(true);
 t := '30833';
 sock.Connect('255.255.255.255', t);
 sock.SendString('Hello');
 start := GetTickCount;
 Repeat
   s := sock.recvpacket(500);
   If s <> '' Then
   Begin
 remoteip := iptostr(ntohl(sock.RemoteSin.sin_addr.s_addr));
 DoSomething;
   End; //if s<>''
   dauer := (gettickcount - start);
 Until (dauer > 2000);
 sock.free;
   Except End;
End;


yours truly,

Arthur Hoornweg



-
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
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public


Re: [Synalist] SynaSer {solved}

2008-11-28 Thread Richard


>   {:stopbit value for 1 stopbit}
>   SB1 = 0;

OK, there I had something wrong in my mind. Sorry, but I relied too
strong on my mind instead of looking it up.
>   {:stopbit value for 1.5 stopbit}
>   SB1andHalf = 1;
>   {:stopbit value for 2 stopbits}
>   SB2 = 2;
It works as it should, thanks to all contributors! The serial port I
used didn't work (though SynaSer showed an "OK"-status), hardware
problem.  I tried the other port and everything was fine...
Thank you! 
Richard
-- 
Richard Müller - Am Spring 9 - D-58802 Balve-Eisborn
Ökologische Station in der JH Sorpesee
www.oeko-sorpe.de - www.wasserreise.info


-
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
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public