🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
15 messages
15 total messages Started by Ori Tue, 29 Aug 2006 09:06
Simple Client - Server example for Builder 4.0 ?
#2046
Author: Ori
Date: Tue, 29 Aug 2006 09:06
13 lines
1299 bytes
Hi,

Can someone please show me or send me a simple code for Client - 
Server example that will work on Builder 4.0 ?  I tried to use
the example from "Indy" --> "BasicClientServer" from Builder 6.0
but I can't open or compile the project, is there anywhere just 
a simple code to demonstrate Client-Server messages sending on
two computers that have local network between them? that will 
work on my Builder 4.0, just a simple code that I can copy-past
and run right away.

Thanks!
Re: Simple Client - Server example for Builder 4.0 ?
#2047
Author: Hans Galema
Date: Tue, 29 Aug 2006 11:53
12 lines
1343 bytes
Ori wrote:

> Can someone please show me or send me a simple code for Client - 
> Server example that will work on Builder 4.0 ? 

Has bcb4 components TServerSocket and TClientSocket on the Internet palette?
If so then there will probably be also the Chat example in
the Examples directory.

Please have a look.

Hans.
Re: Simple Client - Server example for Builder 4.0 ?
#2048
Author: Ori
Date: Tue, 29 Aug 2006 12:49
28 lines
1484 bytes
Thanks Hans, I don't see any Internet palette on my builder, but
on the 'System' palette I can see the components - 

1. DdeClientConv. 

2. DdeClientItem. 

3. DdeServerConv. 

4. DdeServerItem.

Can I do something with them? or do you have any example on 
your PC that you can send me by e-mail? I need something for 
my Builder 4.0

Thanks :-) 


Hans Galema <notused@notused.nl> wrote:
>
>Has bcb4 components TServerSocket and TClientSocket on the Internet palette?
>If so then there will probably be also the Chat example in
>the Examples directory.
>
>Please have a look.
>
>Hans.
Re: Simple Client - Server example for Builder 4.0 ?
#2050
Author: Michel Leunen
Date: Tue, 29 Aug 2006 15:15
14 lines
1477 bytes
Ori wrote:
> I don't see any Internet palette on my builder

Which version do you have. I don't think the personal one has the 
Internet palette. IIRC, you must have at least the Pro version.

Michel
-- 
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
Re: Simple Client - Server example for Builder 4.0 ?
#2051
Author: Bob Gonder
Date: Tue, 29 Aug 2006 16:39
15 lines
1480 bytes
Ori wrote:

>Can someone please show me or send me a simple code for Client - 
>Server example that will work on Builder 4.0 ?  

You already have one.
The MSDN links you posted should work for you once you remove the
function that doesn't compile (getaddrinfo), and replace

    ListenSocket = socket(result->ai_family, result->ai_socktype,
result->ai_protocol);

with

   ListenSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
Re: Simple Client - Server example for Builder 4.0 ?
#2053
Author: Hans Galema
Date: Tue, 29 Aug 2006 18:12
7 lines
1090 bytes
Ori wrote:

> Can I do something with them? 

No.

Hans.
Re: Simple Client - Server example for Builder 4.0 ?
#2056
Author: Ori
Date: Wed, 30 Aug 2006 07:44
75 lines
3009 bytes
>The MSDN links you posted should work for you once you remove the
>function that doesn't compile (getaddrinfo), and replace
>
>    ListenSocket = socket(result->ai_family, result->ai_socktype,
>result->ai_protocol);
>
>with
>
>   ListenSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );


Hi Bob, I'm still having problems with this code, after I 
replaced the function that you told me I still had more errors 
and warnings, for example it don't know the function 
freeaddrinfo() so I just deleted it, after I managed at last to 
run the code then the program return from the function with an 
error after the line - 

 iResult = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); 

the error code keep changing all the time, it's looks like it's 
rising each time when I do "Build all", for example if I run 
the program several times I'm getting the same error code, but
once when I do "Build all" and tun it again I get another error
code, here are some of the error codes that I got - 

 15196, 17244, 19292, 21340....

What can be the problem? here is my code until the return point 
with the error - 


void __fastcall TForm1::SpeedButton1Click( TObject *Sender )
{
  WSADATA wsaData;
  SOCKET ConnectSocket = INVALID_SOCKET;
  struct addrinfo *result = NULL, *ptr = NULL, hints;
  char *sendbuf = "this is a test";
  char recvbuf[DEFAULT_BUFLEN];
  int iResult;
  int recvbuflen = DEFAULT_BUFLEN;

  // Validate the parameters
  // Initialize Winsock
  iResult = WSAStartup( MAKEWORD( 2, 2 ), &wsaData );

  if ( iResult != 0 )
  {
    printf( "WSAStartup failed: %d\n", iResult );
    return;
  }

  ZeroMemory( &hints, sizeof(hints) );
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;

//Resolve the server address and port
//iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);
  iResult = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

  if ( iResult != 0 )
  {
    printf( "getaddrinfo failed: %d\n", iResult );
    WSACleanup();
    return;
  }

   .  
   .  
   .  
   .  
   .  
}
Re: Simple Client - Server example for Builder 4.0 ?
#2055
Author: Ori
Date: Wed, 30 Aug 2006 08:01
12 lines
1189 bytes
>Which version do you have. I don't think the personal one has the 
>Internet palette. IIRC, you must have at least the Pro version.
>
>Michel


Borland C++ Builder, Standard version 4.00

That's what I see in the 'About' window.

ori.
Re: Simple Client - Server example for Builder 4.0 ?
#2057
Author: Bob Gonder
Date: Wed, 30 Aug 2006 14:02
98 lines
3804 bytes
Ori wrote:

>
>>The MSDN links you posted should work for you once you remove the
>>function that doesn't compile (getaddrinfo), and replace
>>
>>    ListenSocket = socket(result->ai_family, result->ai_socktype,
>>result->ai_protocol);
>>
>>with
>>
>>   ListenSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
>
>
>Hi Bob, I'm still having problems with this code, after I 
>replaced the function that you told me I still had more errors 

Well, that's not what I told you to do.

First, remove getaddrinfo, and all references to it.
And all addrinfo variables.
And all code that use them.
And all code that checks the return for errors from getaddrinfo.

Obliterate addrinfo from the program.

Then. you will be left with a ListenSocket = socket(); because
"result" is an addrinfo which you have deleted.
You will re-write that one function as
   ListenSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );


>and warnings, for example it don't know the function 
>freeaddrinfo() so I just deleted it, after I managed at last to 
>run the code then the program return from the function with an 
>error after the line - 
>
> iResult = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); 

Why are you doing iResult?
Is that what I wrote above?

>
>the error code keep changing all the time, it's looks like it's 

That's because it isn't an error code. It is a socket handle.
Read the actual description of the functions you are using.

>void __fastcall TForm1::SpeedButton1Click( TObject *Sender )
>{
>  WSADATA wsaData;
>  SOCKET ConnectSocket = INVALID_SOCKET;

Remove addrinfo
////>  struct addrinfo *result = NULL, *ptr = NULL, hints;

>  char *sendbuf = "this is a test";
>  char recvbuf[DEFAULT_BUFLEN];
>  int iResult;
>  int recvbuflen = DEFAULT_BUFLEN;
>
>  // Validate the parameters
>  // Initialize Winsock
>  iResult = WSAStartup( MAKEWORD( 2, 2 ), &wsaData );
>
>  if ( iResult != 0 )
>  {
>    printf( "WSAStartup failed: %d\n", iResult );
>    return;
>  }
>
Remove addrinfo
////>  ZeroMemory( &hints, sizeof(hints) );
////>  hints.ai_family = AF_UNSPEC;
////>  hints.ai_socktype = SOCK_STREAM;
////>  hints.ai_protocol = IPPROTO_TCP;
>
////>//Resolve the server address and port
////>//iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);

This isn't what I said to do
////>  iResult = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
>
Remove addrinfo
////>  if ( iResult != 0 )
////>  {
////>    printf( "getaddrinfo failed: %d\n", iResult );
////>    WSACleanup();
////>    return;
////>  }
>
>   .  
Down here somewhere is the line I told you to replace
>   .  
>   .  
>   .  
>   .  
>}
Re: Simple Client - Server example for Builder 4.0 ?
#2064
Author: Ori
Date: Thu, 31 Aug 2006 07:01
6 lines
1189 bytes
>Well, that's not what I told you to do...

Sorry Bob you are absolutely right, how stupid of me, later when
I'll have time I'll fix the code in a better way and I'll let 
you know, thanks very very much :-)
Re: Simple Client - Server example for Builder 4.0 ?
#2068
Author: Mark Jacobs
Date: Thu, 31 Aug 2006 10:38
11 lines
1532 bytes
Ori wrote:
> Borland C++ Builder, Standard version 4.00
> That's what I see in the 'About' window.

You need Pro to work with Sockets, so you'll have to upgrade. Buy Highlander 
when it comes out in January 2007   ;-)
-- 

Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
Re: Simple Client - Server example for Builder 4.0 ?
#2069
Author: Mark Jacobs
Date: Thu, 31 Aug 2006 10:40
13 lines
1659 bytes
Ori wrote:
>> Well, that's not what I told you to do...
> 
> Sorry Bob you are absolutely right, how stupid of me, later when
> I'll have time I'll fix the code in a better way and I'll let
> you know, thanks very very much :-)

We will be eagerly awaiting your findings.
-- 
 
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
Re: Simple Client - Server example for Builder 4.0 ?
#2070
Author: Ori
Date: Thu, 31 Aug 2006 11:40
9 lines
1228 bytes
>You need Pro to work with Sockets, so you'll have to upgrade. 
>
>We will be eagerly awaiting your findings.


So... can I or can't I test this Client-Server code on my PC ? 

  :-/
Re: Simple Client - Server example for Builder 4.0 ?
#2071
Author: Mark Jacobs
Date: Thu, 31 Aug 2006 13:39
19 lines
2258 bytes
Ori wrote:
> So... can I or can't I test this Client-Server code on my PC ?

If your copy of BCB does not have an Internet tab on the component palette, 
then I would recommend you upgrade to BCB5 Pro or higher in order to reap the 
benefits of programming with TClientSocket and TServerSocket - they make 
TCP/IP programming much easier. The code example cited earlier is nothing to 
do with me, and it looks far more complicated that any code that I have 
written using TClientSocket and TServerSocket to stream sound. I can only 
conclude that, with client-server programs, the design of their inner workings 
is the most important factor in terms of ease of writing and maintenance of 
that code. I got the client and the server the right way round! The program 
that monitors several stations should be a client, and the monitored stations 
should be servers. (That's a clue, by the way!)
-- 

Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
Re: Simple Client - Server example for Builder 4.0 ?
#2073
Author: Ori
Date: Thu, 31 Aug 2006 15:00
13 lines
1480 bytes
Thanks Mark :-) what was the clue? that you can send me the code
for it? I'll send a new question in a few minutes please have
a look.

Ori.


>I got the client and the server the right way round! The program 
>that monitors several stations should be a client, and the monitored stations 
>should be servers. (That's a clue, by the way!)
>
>Mark Jacobs
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads