Apologies for reposting this, but I'm still stumped.
still getting to grips with the rabbit...
I'd like to service 2 or more tcp connections simultaneously (max of
about
4).
I thought the example shown on page 37 of the dynamic c tcp/ip users manual
would do the trick, but it only allows one port to be open at any one time.
I've added the code below - what do I need to do to get it to service
both
ports simultaneously?
thanks,
Jim
#define TCPCONFIG 1
#define PORT1 3246
#define PORT2 6786
#define SOCK_BUF_SIZE 2048
#define MAX_SOCKETS 2
#memmap xmem
#use "dcrtcp.lib"
tcp_Socket Socket_1;
tcp_Socket Socket_2;
#define MAX_BUFSIZE 512
char buf1[MAX_BUFSIZE], buf2[MAX_BUFSIZE];
cofunc int basic_tcp[2](tcp_Socket *s, int port, char *buf)
{
auto int length, space_available;
tcp_listen(s, port, 0, 0, NULL, 0);
while((-1 == sock_bytesready(s)) && (0 == sock_established(s)))
yield;
while(sock_established(s))
{
space_available = sock_tbleft(s);
if (space_available > (MAX_BUFSIZE - 1))
space_available = (MAX_BUFSIZE - 1);
length = sock_fastread(s, buf, space_available);
if (length > 0)
{
buf[length] = '\0';
printf("%s", buf);
sock_fastwrite(s, buf, length);
}
yield;
}
sock_close(s);
return 1;
}
main()
{
auto int x;
auto char z[20];
auto char test[20];
auto char display[128];
auto char channels[8];
auto int src,dest;
brdInit(); //initialize board for this demo
serDopen(9600);
serCopen(9600);
sock_init();
while (1)
{
costate
{
wfd basic_tcp[0](&Socket_1, PORT1, buf1);
}
costate
{
wfd basic_tcp[1](&Socket_2, PORT2, buf2);
}
costate
{
tcp_tick(NULL);
}
costate
{
waitfor(DelayMs(100));
}
}
---
Maintech Communications
41 Woodend Drive
Jordanhill
Glasgow
G13 1QJ
Tel/Fax: +44 (0)709 222 6426
jim.main@jim....
multiple sockets on tcp/ip problem
Started by ●August 27, 2004
Reply by ●August 27, 20042004-08-27
Just shooting in the dark, but maybe you need:
#define MAX_TCP_SOCKET_BUFFERS 2
Prior to the #use "dcrtcp.lib" (unless that MAX_SOCKETS is the same thing.)
Dunno about the cofunc array...maybe pull that part out into individual
functions to make sure you have the networking part working before cofuncing
things?
> -----Original Message-----
> From: Jim Main [mailto:jim.main@jim....]
> Sent: Friday, August 27, 2004 9:09 AM
> To: Rabbit forum
> Subject: [rabbit-semi] multiple sockets on tcp/ip problem
>
> Apologies for reposting this, but I'm still stumped.
>
> still getting to grips with the rabbit...
>
> I'd like to service 2 or more tcp connections simultaneously
> (max of about 4).
>
> I thought the example shown on page 37 of the dynamic c
> tcp/ip users manual would do the trick, but it only allows
> one port to be open at any one time.
> I've added the code below - what do I need to do to get it to
> service both ports simultaneously?
>
> thanks,
>
> Jim
>
> #define TCPCONFIG 1
> #define PORT1 3246
> #define PORT2 6786
>
> #define SOCK_BUF_SIZE 2048
> #define MAX_SOCKETS 2
>
> #memmap xmem
> #use "dcrtcp.lib"
>
> tcp_Socket Socket_1;
> tcp_Socket Socket_2;
>
> #define MAX_BUFSIZE 512
>
> char buf1[MAX_BUFSIZE], buf2[MAX_BUFSIZE];
>
> cofunc int basic_tcp[2](tcp_Socket *s, int port, char *buf) {
> auto int length, space_available;
>
> tcp_listen(s, port, 0, 0, NULL, 0);
>
> while((-1 == sock_bytesready(s)) && (0 == sock_established(s)))
> yield;
> while(sock_established(s))
> {
> space_available = sock_tbleft(s);
> if (space_available > (MAX_BUFSIZE - 1))
> space_available = (MAX_BUFSIZE - 1);
>
> length = sock_fastread(s, buf, space_available);
> if (length > 0)
> {
> buf[length] = '\0';
> printf("%s", buf);
> sock_fastwrite(s, buf, length);
> }
> yield;
> }
> sock_close(s);
> return 1;
> } > main()
> {
>
> auto int x;
> auto char z[20];
> auto char test[20];
> auto char display[128];
> auto char channels[8];
> auto int src,dest;
>
> brdInit(); //initialize board for this demo
>
> serDopen(9600);
> serCopen(9600);
>
> sock_init();
>
> while (1)
> {
> costate
> {
> wfd basic_tcp[0](&Socket_1, PORT1, buf1);
> }
>
> costate
> {
> wfd basic_tcp[1](&Socket_2, PORT2, buf2);
> }
> costate
> {
> tcp_tick(NULL);
> }
> costate
> {
> waitfor(DelayMs(100));
> }
> }
>
> ---
> Maintech Communications
> 41 Woodend Drive
> Jordanhill
> Glasgow
> G13 1QJ
>
> Tel/Fax: +44 (0)709 222 6426
>
> jim.main@jim.... > ------------------------ Yahoo! Groups Sponsor
> --------------------~-->
> $9.95 domain names from Yahoo!. Register anything.
> http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dN_tlB/TM
> --------------------------
> ------~- > Yahoo! Groups Links >
#define MAX_TCP_SOCKET_BUFFERS 2
Prior to the #use "dcrtcp.lib" (unless that MAX_SOCKETS is the same thing.)
Dunno about the cofunc array...maybe pull that part out into individual
functions to make sure you have the networking part working before cofuncing
things?
> -----Original Message-----
> From: Jim Main [mailto:jim.main@jim....]
> Sent: Friday, August 27, 2004 9:09 AM
> To: Rabbit forum
> Subject: [rabbit-semi] multiple sockets on tcp/ip problem
>
> Apologies for reposting this, but I'm still stumped.
>
> still getting to grips with the rabbit...
>
> I'd like to service 2 or more tcp connections simultaneously
> (max of about 4).
>
> I thought the example shown on page 37 of the dynamic c
> tcp/ip users manual would do the trick, but it only allows
> one port to be open at any one time.
> I've added the code below - what do I need to do to get it to
> service both ports simultaneously?
>
> thanks,
>
> Jim
>
> #define TCPCONFIG 1
> #define PORT1 3246
> #define PORT2 6786
>
> #define SOCK_BUF_SIZE 2048
> #define MAX_SOCKETS 2
>
> #memmap xmem
> #use "dcrtcp.lib"
>
> tcp_Socket Socket_1;
> tcp_Socket Socket_2;
>
> #define MAX_BUFSIZE 512
>
> char buf1[MAX_BUFSIZE], buf2[MAX_BUFSIZE];
>
> cofunc int basic_tcp[2](tcp_Socket *s, int port, char *buf) {
> auto int length, space_available;
>
> tcp_listen(s, port, 0, 0, NULL, 0);
>
> while((-1 == sock_bytesready(s)) && (0 == sock_established(s)))
> yield;
> while(sock_established(s))
> {
> space_available = sock_tbleft(s);
> if (space_available > (MAX_BUFSIZE - 1))
> space_available = (MAX_BUFSIZE - 1);
>
> length = sock_fastread(s, buf, space_available);
> if (length > 0)
> {
> buf[length] = '\0';
> printf("%s", buf);
> sock_fastwrite(s, buf, length);
> }
> yield;
> }
> sock_close(s);
> return 1;
> } > main()
> {
>
> auto int x;
> auto char z[20];
> auto char test[20];
> auto char display[128];
> auto char channels[8];
> auto int src,dest;
>
> brdInit(); //initialize board for this demo
>
> serDopen(9600);
> serCopen(9600);
>
> sock_init();
>
> while (1)
> {
> costate
> {
> wfd basic_tcp[0](&Socket_1, PORT1, buf1);
> }
>
> costate
> {
> wfd basic_tcp[1](&Socket_2, PORT2, buf2);
> }
> costate
> {
> tcp_tick(NULL);
> }
> costate
> {
> waitfor(DelayMs(100));
> }
> }
>
> ---
> Maintech Communications
> 41 Woodend Drive
> Jordanhill
> Glasgow
> G13 1QJ
>
> Tel/Fax: +44 (0)709 222 6426
>
> jim.main@jim.... > ------------------------ Yahoo! Groups Sponsor
> --------------------~-->
> $9.95 domain names from Yahoo!. Register anything.
> http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dN_tlB/TM
> --------------------------
> ------~- > Yahoo! Groups Links >
Reply by ●August 27, 20042004-08-27
I'm pretty sure MAX_SOCKETS would be the
same thing. I tried MAX_TCP_SOCKET_BUFFERS, to no
avail.
I'll try the whole thing without
costatements - I can't see why it won't work though.
Thanks,
Jim
---
Jim Main
Jim Main
----- Original Message -----From: Dave MooreTo: r...@yahoogroups.comSent: Friday, August 27, 2004 6:12 PMSubject: RE: [rabbit-semi] multiple sockets on tcp/ip problemJust shooting in the dark, but maybe you need:
#define MAX_TCP_SOCKET_BUFFERS 2
Prior to the #use "dcrtcp.lib" (unless that MAX_SOCKETS is the same thing.)
Dunno about the cofunc array...maybe pull that part out into individual
functions to make sure you have the networking part working before cofuncing
things?
> -----Original Message-----
> From: Jim Main [mailto:j...@maintech.co.uk]
> Sent: Friday, August 27, 2004 9:09 AM
> To: Rabbit forum
> Subject: [rabbit-semi] multiple sockets on tcp/ip problem
>
> Apologies for reposting this, but I'm still stumped.
>
> still getting to grips with the rabbit...
>
> I'd like to service 2 or more tcp connections simultaneously
> (max of about 4).
>
> I thought the example shown on page 37 of the dynamic c
> tcp/ip users manual would do the trick, but it only allows
> one port to be open at any one time.
> I've added the code below - what do I need to do to get it to
> service both ports simultaneously?
>
> thanks,
>
> Jim
>
> #define TCPCONFIG 1
> #define PORT1 3246
> #define PORT2 6786
>
> #define SOCK_BUF_SIZE 2048
> #define MAX_SOCKETS 2
>
> #memmap xmem
> #use "dcrtcp.lib"
>
> tcp_Socket Socket_1;
> tcp_Socket Socket_2;
>
> #define MAX_BUFSIZE 512
>
> char buf1[MAX_BUFSIZE], buf2[MAX_BUFSIZE];
>
> cofunc int basic_tcp[2](tcp_Socket *s, int port, char *buf) {
> auto int length, space_available;
>
> tcp_listen(s, port, 0, 0, NULL, 0);
>
> while((-1 == sock_bytesready(s)) && (0 == sock_established(s)))
> yield;
> while(sock_established(s))
> {
> space_available = sock_tbleft(s);
> if (space_available > (MAX_BUFSIZE - 1))
> space_available = (MAX_BUFSIZE - 1);
>
> length = sock_fastread(s, buf, space_available);
> if (length > 0)
> {
> buf[length] = '\0';
> printf("%s", buf);
> sock_fastwrite(s, buf, length);
> }
> yield;
> }
> sock_close(s);
> return 1;
> }> main()
> {
>
> auto int x;
> auto char z[20];
> auto char test[20];
> auto char display[128];
> auto char channels[8];
> auto int src,dest;
>
> brdInit(); //initialize board for this demo
>
> serDopen(9600);
> serCopen(9600);
>
> sock_init();
>
> while (1)
> {
> costate
> {
> wfd basic_tcp[0](&Socket_1, PORT1, buf1);
> }
>
> costate
> {
> wfd basic_tcp[1](&Socket_2, PORT2, buf2);
> }
> costate
> {
> tcp_tick(NULL);
> }
> costate
> {
> waitfor(DelayMs(100));
> }
> }
>
> ---
> Maintech Communications
> 41 Woodend Drive
> Jordanhill
> Glasgow
> G13 1QJ
>
> Tel/Fax: +44 (0)709 222 6426
>
> j...@maintech.co.uk> ------------------------ Yahoo! Groups Sponsor
> --------------------~-->
> $9.95 domain names from Yahoo!. Register anything.
> http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/dN_tlB/TM
> --------------------------
> ------~->
>
>
> Yahoo! Groups Links>
>