PDA

Tam Sürümünü Görmek İçin : Socket Programming??


JAKOB_BG
08/05/2004, 21:57
Hi folks,
I'm triying to send message form the client to the server in BCB 6.0 but when I send the message I got immediately "Error receiving" I couldn't find where is the wrong..
Any answer will appreciate..

My code look like this
--- client ---

bool __fastcall SendBuffer(TCustomWinSocket *Socket, void *Buffer, int
Length)
{
int Sent = 0;
int Total_Sent = 0;
BYTE *Buf = (LPBYTE)Buffer;

while( Total_Sent < Length )
{
Sent = Socket->SendBuf(&Buf[Total_Sent], Length - Total_Sent);
if( Sent <= 0 )
{
if( WSAGetLastError() == WSAEWOULDBLOCK )
continue;
return false;
}
Total_Sent += Sent;
}
return true;
}

//...

AnsiString text = Edit1->Text;
int length = text.Length();

bool ok = SendBuffer(Form1->ClientSocket1->Socket, &length,
sizeof(int));
if( ok )
ok = SendBuffer(Form1->ClientSocket1->Socket, text.c_str(), length);
if( !ok )
ShowMessage("Error");


--- server ---

bool __fastcall ReadBuffer(TCustomWinSocket *Socket, void *Buffer, int
Length)
{
int Read = 0;
int Total_Read = 0;
BYTE *Buf = (LPBYTE)Buffer;

while( Total_Read < Length )
{
Read = Socket->ReceiveBuf(&Buf[Total_Read], Length -
Total_Read);
if( Read <= 0 )
{
if( WSAGetLastError() == WSAEWOULDBLOCK )
continue;
return false;
}
Total_Read += Read;
}
return true;
}

//...

AnsiString buffer;
int length = 0;

bool ok = ReadBuffer(Socket, &length, sizeof(int));
if( ok )
{
buffer.SetLength(length);
ok = ReadBuffer(Socket, buffer.c_str(), length);
}
if( !ok )
ShowMessage("Error receiving");

Thanks in Advance
BigSky_(*


Euclides
08/05/2004, 22:30
1....
...
2...
...

Kögüdey Meygen
09/05/2004, 00:54
Türkçe bilmiyor musunuz?
--------------
int __fastcall SendBuffer(TCustomWinSocket *Socket, void *Buffer, int
Length)
{
int Sent = 0;
int Total_Sent = 0;
BYTE *Buf = (LPBYTE)Buffer;

int hata = 0;

while( Total_Sent < Length )
{
Sent = Socket->SendBuf(&Buf[Total_Sent], Length - Total_Sent);
if( Sent <= 0 )
{
if( (hata = WSAGetLastError()) == WSAEWOULDBLOCK )
continue;
return hata;
}
Total_Sent += Sent;
}
return 0;
}

//...

AnsiString text = Edit1->Text;
int length = text.Length();
char hatabildiri[32];

int ok = SendBuffer(Form1->ClientSocket1->Socket, &length,
sizeof(int));
if( ok==0 )
{
ok = SendBuffer(Form1->ClientSocket1->Socket, text.c_str(), length);
if( ok!=0 )
{
sprintf(hatabildiri,"%d.satirda hata:%d ",__LINE__,ok);
ShowMessage(hatabildiri);
}
}
else
{
sprintf(hatabildiri,"%d.satirda hata:%d ",__LINE__,ok);
ShowMessage(hatabildiri);
}



--- server ---

int __fastcall ReadBuffer(TCustomWinSocket *Socket, void *Buffer, int
Length)
{
int Read = 0;
int Total_Read = 0;
BYTE *Buf = (LPBYTE)Buffer;
int hata = 0;
while( Total_Read < Length )
{
Read = Socket->ReceiveBuf(&Buf[Total_Read], Length -
Total_Read);
if( Read <= 0 )
{
if( (hata = WSAGetLastError()) == WSAEWOULDBLOCK )
continue;
return hata;
}
Total_Read += Read;
}
return 0;
}

//...

AnsiString buffer;
int length = 0;
char hatabildiri[32];

int ok = ReadBuffer(Socket, &length, sizeof(int));
if( ok==0 )
{
buffer.SetLength(length);
ok = ReadBuffer(Socket, buffer.c_str(), length);
if( ok!=0 )
{
sprintf(hatabildiri,"%d.satirda hata:%d ",__LINE__,ok);
ShowMessage(hatabildiri);
}
}
else
{
sprintf(hatabildiri,"%d.satirda hata:%d ",__LINE__,ok);
ShowMessage(hatabildiri);
}


Sonrada Microsoft MSDN library "Windows sockets error codes" tan hata numarasına bakabilirsiniz.
MSDN belgeleri yoksa, hata numarısını buraya yazın, ondan sonra yardımcı olabilirim belki?

JAKOB_BG
10/05/2004, 22:40
Tesekkurler,[ Siposibo ;-) ]
Aslinda kod calisiyor ama mesaj alindiktan sonra niye hata veriyor anlamiyorum
sanirim hata burada
> if( Read <= 0 )
>{
>if( (hata = WSAGetLastError()) == WSAEWOULDBLOCK )
>continue;
>return false;
meydana geliyor ama niye?Dedigim gibi mesaji dogruca aldiktan sonra niye hata mesaji veriyor tuhaf.

Cekici
10/05/2004, 22:46
Türkçe bilmiyor musunuz?
niye uğraştırıyorlar adamı bilmem...

Kögüdey Meygen
11/05/2004, 09:35
Hata kodu tam olarak ne?
printf("%d",hata);

JAKOB_BG
12/05/2004, 23:54
Tesekkurler,
Sizin verdiginiz kodlari ekledikten sonra hata vermedi bakalim ilerleyen gunlerde ne olacak..
Gorusmek uzere.
BigSky_(*_

101
22/06/2004, 14:59
Türkçe bir forumda yakışmamış ing. mesaj atmak.