Board index » cppbuilder » Socket problem setting port and connecting.

Socket problem setting port and connecting.


2005-04-18 06:26:18 PM
cppbuilder6
I wrote a small server, executing just ServerSocket1->Open();
I wrote a small client :
ClientSocket1->Address = "192.168.0.2";
ClientSocket1->Port = 1234;
ClientSocket1->Open();
only i get a compilation error :
[Linker Error] Unresolved external '__fastcall
Scktcomp::TAbstractSocket::SetPortA(int)' referenced from BUILDERINO.OBJ.
I looked for a patch that should solve it but the borland page that should
contain it has gone offline.
When i remove the line ClientSocket1->Port = 1234; i get an error :
Project builderino.exe raised exception class ESocketError with message
'Asynchronous socket error 10049'. Process stopped. Use Step or Run to
continue.
I looked up error 10049 and it says that my address isn't set right.
I use Builder 4 and run out of idears. Any help is appreciated.
 
 

Re:Socket problem setting port and connecting.

longshot wrote:
Quote
ClientSocket1->Port = 1234;
[Linker Error] Unresolved external '__fastcall
Scktcomp::TAbstractSocket::SetPortA(int)' referenced from BUILDERINO.OBJ.
Yes. I remember that from bcb3.
Quote
I looked for a patch that should solve it but the borland page that should
contain it has gone offline.
Looking for a patch was a good idea because, if I remember well, the
error was gone when a bcb3 patch was applied.
Quote
When i remove the line ClientSocket1->Port = 1234; i get an error :

Project builderino.exe raised exception class ESocketError with message
'Asynchronous socket error 10049'. Process stopped. Use Step or Run to
continue.
But you can set the Port at designtime with the Object Inspector too.
Quote
I looked up error 10049 and it says that my address isn't set right.
Port was not filled in in the IDE then.
Hans.
 

Re:Socket problem setting port and connecting.

hello,
I'm new in socket's programing..
I'm trying to send data using ClientSocket/ServerSocket with Remy's code,
but how and where to specify port and address in client and server pc?
server's pc adrres 192.168.0.1
client 192.168.0.2
i'm getting 10049 10061 erros :(
sorry 4 poor english
"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
longshot wrote:

>ClientSocket1->Port = 1234;

>[Linker Error] Unresolved external '__fastcall
>Scktcomp::TAbstractSocket::SetPortA(int)' referenced from BUILDERINO.OBJ.

Yes. I remember that from bcb3.

>I looked for a patch that should solve it but the borland page that
>should
>contain it has gone offline.

Looking for a patch was a good idea because, if I remember well, the
error was gone when a bcb3 patch was applied.

>When i remove the line ClientSocket1->Port = 1234; i get an error :
>
>Project builderino.exe raised exception class ESocketError with message
>'Asynchronous socket error 10049'. Process stopped. Use Step or Run to
>continue.

But you can set the Port at designtime with the Object Inspector too.

>I looked up error 10049 and it says that my address isn't set right.

Port was not filled in in the IDE then.

Hans.
 

{smallsort}

Re:Socket problem setting port and connecting.

"Egi2kaZz" < XXXX@XXXXX.COM >wrote in message
Quote
how and where to specify port and address in client and server pc?
TClientSocket has Address/Host and Port properties. You can set them any
time prior to connecting to the server.
TServerSocket has a Port property. You can set it any time prior to
activating the server.
Quote
i'm getting 10049 10061 erros :(
WSAEADDRNOTAVAIL (10049)
Cannot assign requested address.
The requested address is not valid in its context. Normally results from
an attempt to bind to an address that is not valid for the local machine, or
connect/sendto an address or port that is not valid for a remote machine
(e.g. port 0).
WSAECONNREFUSED (10061)
Connection refused.
No connection could be made because the target machine actively refused
it. This usually results from trying to connect to a service that is
inactive on the foreign host - i.e. one with no server application running.
Gambit
 

Re:Socket problem setting port and connecting.

thanx, that codes works fine, but every time y receive file, I have
to do :
try {
ReadStream(Socket, file);
}
__finally {
delete file;
ClientSocket1->Active=false;
Memo1->Lines->Add("file received");
ClientSocket1->Active=true;
}
if I don't inactive ClientSocket my progmam fails :(
void __fastcall TForm1::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
Memo1->Lines->Add("client connected");
}
void __fastcall TForm1::ServerSocket1ClientDisconnect(TObject *Sender,
TCustomWinSocket *Socket)
{
Memo1->Lines->Add("client disconnected");
}
and every time then I send file, My client has to disconnect and then
connect again?
One more thing, then I'm sending files, chating and etc. over Client/Server
Socket's that protocol I am using?
thanx 4 answers
e.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Egi2kaZz" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>how and where to specify port and address in client and server pc?

TClientSocket has Address/Host and Port properties. You can set them any
time prior to connecting to the server.

TServerSocket has a Port property. You can set it any time prior to
activating the server.

>i'm getting 10049 10061 erros :(

WSAEADDRNOTAVAIL (10049)

Cannot assign requested address.

The requested address is not valid in its context. Normally results
from
an attempt to bind to an address that is not valid for the local machine,
or
connect/sendto an address or port that is not valid for a remote machine
(e.g. port 0).


WSAECONNREFUSED (10061)

Connection refused.

No connection could be made because the target machine actively refused
it. This usually results from trying to connect to a service that is
inactive on the foreign host - i.e. one with no server application
running.


Gambit


 

Re:Socket problem setting port and connecting.

"Egi2kaZz" < XXXX@XXXXX.COM >wrote in message
Quote
thanx, that codes works fine, but every time y receive
file, I have to do :
No, you don't.
Quote
if I don't inactive ClientSocket my progmam fails :(
Please provide more details.
Quote
and every time then I send file, My client has to disconnect and then
connect again?
No, it does not. If it does, then your own code is messing it up.
Gambit
 

Re:Socket problem setting port and connecting.

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Egi2kaZz" < XXXX@XXXXX.COM >wrote in message
news:426e472d$ XXXX@XXXXX.COM ...

>thanx, that codes works fine, but every time y receive
>file, I have to do :

No, you don't.

>if I don't inactive ClientSocket my progmam fails :(

Please provide more details.
Well I'm using your code posted 2005 01 11 "please help me..socket file
transfer "
And if don't use:
try {
ReadStream(Socket, file);
}
__finally {
delete file;
ClientSocket1->Active=false; <----
}
Client's program crashes with no responding :(
I'm using 1024 port and stNonBlocking type..
Quote

>and every time then I send file, My client has to disconnect and then
>connect again?

No, it does not. If it does, then your own code is messing it up.


Gambit


 

Re:Socket problem setting port and connecting.

"Egi2kaZz" < XXXX@XXXXX.COM >wrote in message
Quote
Well I'm using your code posted 2005 01 11 "please help
me..socket file transfer "
Ok.
Quote
And if don't use:
<snip>
Client's program crashes with no responding :(
You need to be more specific. What does all of the client's reading code
look like? What is happening when it crashes? Are there any error
messages? Please show code for both parties that actually compiles.
Gambit
 

Re:Socket problem setting port and connecting.

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Egi2kaZz" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>Well I'm using your code posted 2005 01 11 "please help
>me..socket file transfer "

Ok.

>And if don't use:
<snip>
>Client's program crashes with no responding :(

You need to be more specific. What does all of the client's reading code
look like? What is happening when it crashes? Are there any error
messages? Please show code for both parties that actually compiles.
client's code:
bool __fastcall ReadRaw(TCustomWinSocket *Socket, LPVOID Buffer,
int
BufSize)
{
int read;
LPBYTE pBuf = (LPBYTE) Buffer;
while( BufSize>0 )
{
read = Socket->ReceiveBuf(pBuf, BufSize);
if( read == -1 )
{
if( WSAGetLastError() != WSAEWOULDBLOCK )
return false;
}
else
{
pBuf += read;
BufSize -= read;
}
}
return true;
}
bool __fastcall ReadStream(TCustomWinSocket *Socket, TStream *Stream)
{
BYTE buf[1024];
int BufSize;
int BytesToRead = 0;
if( !ReadRaw(Socket, &BytesToRead, sizeof(int)) )
return false;
while( BytesToRead>0 )
{
if( BytesToRead>= 1024 )
BufSize = 1024;
else
BufSize = BytesToRead;
if( !ReadRaw(Socket, buf, BufSize) )
return false;
Stream->Write(buf, BufSize);
BytesToRead -= BufSize;
}
return true;
}
void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
TFileStream *file = new TFileStream("film.avi",fmCreate);
try {
ReadStream(Socket, file);
}
__finally {
delete file;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ClientSocket1->Host = "192.168.0.1";
ClientSocket1->Address = "192.168.0.22";
ClientSocket1->Active = true;
}
//---------------------------------------------------------------------------
Server's code:
bool __fastcall SendRaw(TCustomWinSocket *Socket, LPVOID Buffer, int
BufSize)
{
int sent;
LPBYTE pBuf = (LPBYTE) Buffer;
while( BufSize>0 )
{
sent = Socket->SendBuf(pBuf, BufSize);
if( sent == -1 )
{
if( WSAGetLastError() != WSAEWOULDBLOCK )
return false;
}
else
{
pBuf += sent;
BufSize -= sent;
}
}
return true;
}
bool __fastcall SendStream(TCustomWinSocket *Socket, TStream *Stream)
{
BYTE buf[1024];
int BytesToSend = (Stream->Size - Stream->Position);
if( !SendRaw(Socket, &BytesToSend, sizeof(int)) )
return false;
while( BytesToSend>0 )
{
int read = Stream->Read(buf, sizeof(buf));
if( read < 1 ) // unexpected end-of-stream
return false;
if( !SendRaw(Socket, buf, read) )
return false;
BytesToSend -= read;
}
return true;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if( OpenDialog1->Execute() )
{
TFileStream* file = new TFileStream(OpenDialog1->FileName,
fmOpenRead);
try
{
if(
!SendStream(ServerSocket1->Socket->Connections[0],file) )
ShowMessage("Could not send file");
}
__finally {
delete file;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ServerSocket1->Active = true;
}
//---------------------------------------------------------------------------
first I start server's program, then client's..I can see that file is
transfering if I send
big file 700mb(it's takes more time:)), in client pc it's growing, BUT in
the end program stop responding
with no errors and then I close it,file became 0,0kb size..
As I mentioned, I if I place:
try {
ReadStream(Socket, file);
}
__finally {
delete file;
ClientSocket1->Active=false; <----
}
then program work's fine, but every time I send file, have to disactive,
active..:(
e.
 

Re:Socket problem setting port and connecting.

Egi2kaZz wrote:
Quote
big file 700mb(it's takes more time:)),
700 milli bit ?
Or do you mean 700 Mb or 700 MB? So Mega bit or Mega Byte ?
I see that you do not care using capitals in your text,
as if this was a chatroom; which it is not. Not using capitals
makes your text difficult to read and is often confusing. But if you
use dimensions you certainly need to take the dicipline to use
capitals if there are.
If it is a 700 MB file then please try that code first with 7 MB.
Hans.
 

Re:Socket problem setting port and connecting.

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
Egi2kaZz wrote:

>big file 700mb(it's takes more time:)),

700 milli bit ?

Or do you mean 700 Mb or 700 MB? So Mega bit or Mega Byte ?

I see that you do not care using capitals in your text,
as if this was a chatroom; which it is not. Not using capitals
makes your text difficult to read and is often confusing. But if you
use dimensions you certainly need to take the dicipline to use
capitals if there are.

If it is a 700 MB file then please try that code first with 7 MB.
I have tried this code with 7MB, 0.5MB and with 700MB, but the problem
is the same, that I had mentioned..
If I inactive Client Socket, code 700MB transfer fine..
Quote

Hans.
 

Re:Socket problem setting port and connecting.

"Egi2kaZz" < XXXX@XXXXX.COM >wrote in message
Quote
client's code:
<snip>
Server's code:
<snip>
You did not answer my questions. You said that the code crashes, but you
did not explain about that. You need to provide details.
Gambit
 

Re:Socket problem setting port and connecting.

Egi2kaZz wrote:
Quote
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ClientSocket1->Host = "192.168.0.1";
ClientSocket1->Address = "192.168.0.22";
ClientSocket1->Active = true;
}
What happend to Port?
You don't show port in your code, but you mentioned 1024 which could
be a bit small.
See this link for a (large) list of registered ports.
www.iana.org/assignments/port-numbers
Pick something that is "unassigned" or that you know won't be a
problem (like PlayStation2)
Quote
TFileStream *file = new TFileStream("film.avi",fmCreate);
try {
ReadStream(Socket, file);
}
__finally {
delete file;
}
Just wondering if "delete file" closes the file first.
The docs only mention that it releases the handle.
Perhaps
FileClose( file->Handle);
delete file;
would fix a part of the problem? ( 0 file size )
 

Re:Socket problem setting port and connecting.

Bob Gonder wrote:
Quote
Egi2kaZz wrote:

>void __fastcall TForm1::FormCreate(TObject *Sender)
>{
>ClientSocket1->Host = "192.168.0.1";
>ClientSocket1->Address = "192.168.0.22";
>ClientSocket1->Active = true;
>}
Do not use both Host and Address. Use only one.
And you can connect to one ip-address only.
Hans.
 

Re:Socket problem setting port and connecting.

Hans Galema wrote:
Quote
Bob Gonder wrote:

>Egi2kaZz wrote:
>
>>void __fastcall TForm1::FormCreate(TObject *Sender)
Do not use FormCreate(). Put such code in the constructor instead.
Hans.