BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Socket problem setting port and connecting.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket)
View previous topic :: View next topic  
Author Message
longshot
Guest





PostPosted: Mon Apr 18, 2005 10:26 am    Post subject: Socket problem setting port and connecting. Reply with quote



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.


Back to top
Hans Galema
Guest





PostPosted: Mon Apr 18, 2005 12:14 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote



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.

Back to top
Egi2kaZz
Guest





PostPosted: Sat Apr 23, 2005 9:27 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote



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" <notused (AT) notused (DOT) nl> wrote

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.



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sun Apr 24, 2005 7:35 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote


"Egi2kaZz" <egi2kas (AT) gmail (DOT) com> wrote


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 Sad

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



Back to top
Egi2kaZz
Guest





PostPosted: Tue Apr 26, 2005 1:50 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote

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)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Egi2kaZz" <egi2kas (AT) gmail (DOT) com> wrote in message
news:426abd97 (AT) newsgroups (DOT) borland.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





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Apr 26, 2005 5:00 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote


"Egi2kaZz" <egi2kas (AT) gmail (DOT) com> wrote


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 Sad

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



Back to top
Egi2kaZz
Guest





PostPosted: Tue Apr 26, 2005 7:12 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote


"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Egi2kaZz" <egi2kas (AT) gmail (DOT) com> wrote in message
news:426e472d$1 (AT) newsgroups (DOT) borland.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 Sad
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





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Apr 26, 2005 9:17 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote


"Egi2kaZz" <egi2kas (AT) gmail (DOT) com> wrote


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 Sad

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



Back to top
Egi2kaZz
Guest





PostPosted: Wed Apr 27, 2005 8:47 am    Post subject: Re: Socket problem setting port and connecting. Reply with quote


"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote

Quote:

"Egi2kaZz" <egi2kas (AT) gmail (DOT) com> wrote in message
news:426e9298 (AT) newsgroups (DOT) borland.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.



Back to top
Hans Galema
Guest





PostPosted: Wed Apr 27, 2005 9:18 am    Post subject: Re: Socket problem setting port and connecting. Reply with quote

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.

Back to top
Egi2kaZz
Guest





PostPosted: Wed Apr 27, 2005 9:36 am    Post subject: Re: Socket problem setting port and connecting. Reply with quote


"Hans Galema" <notused (AT) notused (DOT) nl> wrote

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.



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Apr 27, 2005 9:58 am    Post subject: Re: Socket problem setting port and connecting. Reply with quote


"Egi2kaZz" <egi2kas (AT) gmail (DOT) com> wrote


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



Back to top
Bob Gonder
Guest





PostPosted: Wed Apr 27, 2005 2:35 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote

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.
http://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 )




Back to top
Hans Galema
Guest





PostPosted: Wed Apr 27, 2005 3:29 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote

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.

Back to top
Hans Galema
Guest





PostPosted: Wed Apr 27, 2005 3:30 pm    Post subject: Re: Socket problem setting port and connecting. Reply with quote

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.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.