473,666 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket.Receive

Hi all

I have a little FTP proggie. It works, on windows xp, but it doesnt work
properly on windows 2000. The first problem i have, is when retrieving a
list of files.
int bytes = cSocket.Receive (buffer, buffer.Length, 0);

this.message += ASCII.GetString (buffer, 0, bytes);

bytes is returned as size 18, my buffer.Length is set at 512, but i only get
18 back. i know for a fact that there is more since it works on my XP
machines. the above piece of code is in a while loop, keeps concatenating
the results to this.message.

so on the windows 2000 platforms i only get back the first file, whereas
with xp i get back the entire list. files are separated by "\r\n".

that is my first error.

the next error is when the cSocket.Receive just hangs. I think this is
because it is blocking itself until there is data to read. but i know there
is data to read, because it works on my XP machines. the programs "comes
back" after 10 mins, which is the connection idle timeout set on the FTP
server.

is there a component i need to install on the 2000 machines?

another peculiar note: I have tested it on four windows 2000 boxes. Two of
the four boxes "hang" for the 10min, where the other two of the four boxes
repond after the first few seconds. although they dont respond in the
desired way. but ALL four windows 2000 boxes only read back the first file.

windows xp works perfectly.

any suggestions are most welcome!

Thanks
Jason
Nov 16 '05 #1
8 9005
Jason <c_*******@migh ty.co.za> wrote:
I have a little FTP proggie. It works, on windows xp, but it doesnt work
properly on windows 2000. The first problem i have, is when retrieving a
list of files.
int bytes = cSocket.Receive (buffer, buffer.Length, 0);

this.message += ASCII.GetString (buffer, 0, bytes);

bytes is returned as size 18, my buffer.Length is set at 512, but i only get
18 back. i know for a fact that there is more since it works on my XP
machines. the above piece of code is in a while loop, keeps concatenating
the results to this.message.
Right. I don't see why that's a problem. Sockets don't guarantee to
return everything in one lump - just loop until you've got everything.
(Oh, and use a StringBuilder instead of string concatenation.)
so on the windows 2000 platforms i only get back the first file, whereas
with xp i get back the entire list. files are separated by "\r\n".

that is my first error.

the next error is when the cSocket.Receive just hangs. I think this is
because it is blocking itself until there is data to read. but i know there
is data to read, because it works on my XP machines.


I suggest you use a network analyser to confirm that, rather than just
XP machines. Perhaps the server is returning different information to
the 2000 boxes?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
I have tried looping

while (cSocket.Availa ble != 0) {
}

yeh, stringbuilder better, thanks. just need to get this working first hehe

so what would you do? i am very new at sockets. for example how would i
check if i have everything or not?

Thanks again

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Jason <c_*******@migh ty.co.za> wrote:
I have a little FTP proggie. It works, on windows xp, but it doesnt work
properly on windows 2000. The first problem i have, is when retrieving a
list of files.
int bytes = cSocket.Receive (buffer, buffer.Length, 0);

this.message += ASCII.GetString (buffer, 0, bytes);

bytes is returned as size 18, my buffer.Length is set at 512, but i only get 18 back. i know for a fact that there is more since it works on my XP
machines. the above piece of code is in a while loop, keeps concatenating the results to this.message.


Right. I don't see why that's a problem. Sockets don't guarantee to
return everything in one lump - just loop until you've got everything.
(Oh, and use a StringBuilder instead of string concatenation.)
so on the windows 2000 platforms i only get back the first file, whereas
with xp i get back the entire list. files are separated by "\r\n".

that is my first error.

the next error is when the cSocket.Receive just hangs. I think this is
because it is blocking itself until there is data to read. but i know there is data to read, because it works on my XP machines.


I suggest you use a network analyser to confirm that, rather than just
XP machines. Perhaps the server is returning different information to
the 2000 boxes?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Jason <c_*******@migh ty.co.za> wrote:
I have tried looping

while (cSocket.Availa ble != 0) {
}
I wouldn't do that - I'd just let the socket block. Just loop around
until you know that you've got everything.
yeh, stringbuilder better, thanks. just need to get this working first hehe

so what would you do? i am very new at sockets. for example how would i
check if i have everything or not?


The protocol should include appropriate data. There's no concept in a
network stream of "the end" until the connection is closed.

I can't remember exactly how FTP works, but I'm sure there'll be
something you can use to detect when you've finished receiving the
current file (or list of files, or whatever).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
thanks!
i think i have got something that may work

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Jason <c_*******@migh ty.co.za> wrote:
I have tried looping

while (cSocket.Availa ble != 0) {
}


I wouldn't do that - I'd just let the socket block. Just loop around
until you know that you've got everything.
yeh, stringbuilder better, thanks. just need to get this working first hehe
so what would you do? i am very new at sockets. for example how would i
check if i have everything or not?


The protocol should include appropriate data. There's no concept in a
network stream of "the end" until the connection is closed.

I can't remember exactly how FTP works, but I'm sure there'll be
something you can use to detect when you've finished receiving the
current file (or list of files, or whatever).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
RFC 959 indicates that the end of line is indicated with a CRLF
sequence.

You can find RFC 959 at:

http://www.w3.org/Protocols/rfc959/

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Jason <c_*******@migh ty.co.za> wrote:
I have tried looping

while (cSocket.Availa ble != 0) {
}


I wouldn't do that - I'd just let the socket block. Just loop around
until you know that you've got everything.
yeh, stringbuilder better, thanks. just need to get this working first hehe
so what would you do? i am very new at sockets. for example how would i
check if i have everything or not?


The protocol should include appropriate data. There's no concept in a
network stream of "the end" until the connection is closed.

I can't remember exactly how FTP works, but I'm sure there'll be
something you can use to detect when you've finished receiving the
current file (or list of files, or whatever).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
sigh, i thought this would work (from MSDN)

// Receive the host home page content and loop until all the data is
received.
Int32 bytes = s.Receive(RecvB ytes, RecvBytes.Lengt h, 0);
strRetPage = "Default HTML page on " + server + ":\r\n";
strRetPage = strRetPage + ASCII.GetString (RecvBytes, 0, bytes);

while (bytes > 0)
{
bytes = s.Receive(RecvB ytes, RecvBytes.Lengt h, 0);
strRetPage = strRetPage + ASCII.GetString (RecvBytes, 0, bytes);
}

but i also get "blocked"

yeh CRLF is "\r\n" which is what separates my file names...

Thanks
Jason

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
RFC 959 indicates that the end of line is indicated with a CRLF
sequence.

You can find RFC 959 at:

http://www.w3.org/Protocols/rfc959/

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Jason <c_*******@migh ty.co.za> wrote:
I have tried looping

while (cSocket.Availa ble != 0) {
}


I wouldn't do that - I'd just let the socket block. Just loop around
until you know that you've got everything.
yeh, stringbuilder better, thanks. just need to get this working first hehe
so what would you do? i am very new at sockets. for example how would i check if i have everything or not?


The protocol should include appropriate data. There's no concept in a
network stream of "the end" until the connection is closed.

I can't remember exactly how FTP works, but I'm sure there'll be
something you can use to detect when you've finished receiving the
current file (or list of files, or whatever).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #7
Jason <c_*******@migh ty.co.za> wrote:
sigh, i thought this would work (from MSDN)

// Receive the host home page content and loop until all the data is
received.
Int32 bytes = s.Receive(RecvB ytes, RecvBytes.Lengt h, 0);
strRetPage = "Default HTML page on " + server + ":\r\n";
strRetPage = strRetPage + ASCII.GetString (RecvBytes, 0, bytes);

while (bytes > 0)
{
bytes = s.Receive(RecvB ytes, RecvBytes.Lengt h, 0);
strRetPage = strRetPage + ASCII.GetString (RecvBytes, 0, bytes);
}

but i also get "blocked"

yeh CRLF is "\r\n" which is what separates my file names...


Yes, you would get blocked - because the server hasn't been told to
close the connection at the end of the request, presumably.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
> while (bytes > 0)
{
bytes = s.Receive(RecvB ytes, RecvBytes.Lengt h, 0);
strRetPage = strRetPage + ASCII.GetString (RecvBytes, 0, bytes);
}

but i also get "blocked"


Yeh. This blocks as you would expect and need. You need it to block as you
never know when the next packet you get. You need to know when you have
read all the data. This would be a determined based on a header that is
passed with a length or after a certain character combination (not sure
about how ftp does this.) I would look a bit more at the rfc, it should be
able to infer when you know you have all the data. The other route is to
use Indy .Net which has an FTP class in it and works well and its free.
Cheers!

--
William Stacey, MVP
Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8721
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects the child socket remains in the CLOSE_WAIT state. Anyone have any idea what's missing? ----------------------------- Socket Code ----------------------------- namespace Sockets { #region Class - SocketClient
3
4626
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data and then fires a datareceived event. Within the waitingloop there is a timeout function, but I want the the 'last-time-socket-used' variable set when the socket is finished sending. When I send by System.Net.Sockets.Socket.Send(buffer()) (<--this...
6
4107
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: Connect Receive response Send Connect ACK
4
2739
by: Qingdong Z. | last post by:
I have an asynchronous Server Socket to push data to client (Socket.BeginSend) when data is available, Meanwhile, the client socket use Synchronous Client Socket to receive the data. I have two questions on this 1. When client socket does not receive data as fast as server, does server socket queues all the data, or just waits? If it queues, this may kill server 2. I declare socket receive buffer big enough, when I call Socket.Receive...
5
11697
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine if , say a chat message "Hi Charlie" has been received completely?
2
702
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no more data to expect). Sometimes, Socket.Available returns 0 but the other end of the connection did not close it ! 2) This class will be used by many other classes so I have to use the
2
4148
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send I get the last chunk of data and am not able to retrieve it anymore cause the socket will be dead. Loop: { socket.Receive <----------- data arrives
2
15324
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I now see the socket.RecieveTimeout 'property' in the visual studio 2005 help documentation (framework 2.0) and it has example of it being used with TCP socket. This propery is also listed as 'new in .net 2.0'. 1) is the socket.RecieveTimeout...
2
5692
by: Rene Sørensen | last post by:
I'm using .NET 2.0 VS 2005 I'm creating a function that dos something similar to the. SmoApplication.EnumAvailableSqlServers() function. But for som resone I get an error or do i?. The problem is that the program just return from the function when it reach the recive part( reviced = socket.Receive(bytBuffer); ), below here you can se the code. I used eathereal to check the package that is send and reviced, that looks all fine. I do...
0
1567
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear William Stacey, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the socket in non-blocking mode by using the proper socket option ( i.e. SO_RCVTIMEO). After which with the use of recv() I am trying to get into the receive mode. Here as the receive time out is being used the socket should come out of the block...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.