vc >> TCP, Sockets, Blocking etc

by Um9i » Sun, 28 Nov 2004 02:15:02 GMT

I'm pretty new to VB .net and Network coding, what I'm trying to do is
interact with a NNTP server to retrieve a list of news groups.

When I run thru' debug I basically get what I'm after, when I run without
debug the results vary - which to me suggests it's some form of sync problem
with my 'writes and reads'.

I've set up a connection to a server and have sent a 'List' command to get a
'group list', I've set up my connection buffer at 32k, I'm assuming I'm
blocking on the stream read, the question is how to I control receiving a
complete returned message - which could be 500k. I've tried various do-loop
controls, some based on MSDN examples such as 'Loop While
NStream.DataAvailable' and the attached which I'd hoped would loop until a
message which was less then the complete buffer was returned - but it all
seems hit and miss.

thanks

Dim numberOfBytesRead As Integer = 0
Dim sb As New StringBuilder

Do
numberOfBytesRead = NStream.Read(bytes, 0, CInt
Connection.ReceiveBufferSize))
If numberOfBytesRead = 0 Then
Exit Do
End If
sb.Append(Encoding.ASCII.GetString(bytes, 0, numberOfBytesRead))
totallength = sb.Length
Loop Until numberOfBytesRead < Connection.ReceiveBufferSize

vc >> TCP, Sockets, Blocking etc

by Carl Daniel [VC++ MVP] » Sun, 28 Nov 2004 02:48:30 GMT



You might want to post to microsoft.public.dotnet.languages.vb. This group
is for C++.

-cd

Similar Threads

1. looking for code sample for non-blocking TCP sockets - CSharp/C#

2. TCP Socket class send() never blocks...

According to the documentation, the Socket.Send() is a blocking call,
however if I perform a Send() with the Server end point physically
unplugged,the Send call does not block, in fact it returns that the
message bytes were successfully sent.

I find this counter intuitive, since TCP should be gurarnteed delivery,
why does the Send() call seem to succeed, even when the end point was
disconnected.

Any Thoughts???

Thanks,
KD

3. read from TCP/IP socket with blocking - CSharp/C#

4. TCP 10055 error for blocking socket

5. Timeout probelm for blocking socket TCP connections

6. Blocking with TCP Sockets

I have a C# program that uses blocking sockets and want to allow the user to
stop the server.  The problem I am having is the socket blocks on
--------------------------------------------------------------
listener = new System.Net.Sockets.TcpListener(6254);
listener.Start();
//skt is a socket
skt =listener.AcceptSocket();  <--- this line blocks
--------------------------------------------------------------
I attempt to stop the thread as follows
--------------------------------------------------------------
if (thListener.ThreadState != System.Threading.ThreadState.Stopped)
//thListener is the offending thread
{
    try{listener.Stop();} //this always works
    catch{System.Diagnostics.Trace.WriteLine("issue");}
    thListener.Abort();
    thListener.Join(2000);
}
--------------------------------------------------------------
I get the following error
--------------------------------------------------------------
System.Net.Sockets.SocketExchange: A blocking operation was interrupted by a
call to WSACancelBlockingCall
at System.Net.Sockets.Socker.Accept()
at System.Net.Sockets.TcpListener.AcceptSocket()
--------------------------------------------------------------
this error is in an OK-only popup box with no title and appears to be coming
out of the "listener" thread

I have not been able to find any information onWSACancelBlockingCall and was
hoping someone else has an idea how to prevent that popup.
Thanks in advance,
~Logan



7. Socket vs TCP socket - CSharp/C#

8. Ending/restarting blocked C# thread using blocking Socket calls

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

Send request for wml page
Receive wml page

Disconnect


Because I am using the blocking Socket calls to connect, send and
receive it is possible for the thread to get stuck in a blocked state.

I would like to be able to figure out when the thread is in the
blocked state and somehow stop/kill and then restart the thread again.

I tried using a System.Timers.Timer to wait on each blocking callIf
the timer interval expired then the Timer Elapsed event would be fired
and I could send an event back to the creator of the thread to kill
and restart the thread (killing via the Thread.Abort method).

However this has created multiple problems (specifically threads never
end up finishing, seemingly getting stuck in an endless loop).

So my questionIs there a way to accomplish this?  Can someone
provide a basic outline or a hint at what methodologies I'm missing?

Many thanks in advance,
roger beniot