473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Socket Blocked on Socket.Receive

My socket application blocked at socket.receiver() after received all
information from sender. Should socket.Receive() return 0 after no
more data available? Note: My socket object was not close on both
client/server side. My cached for further use.

While bytesReceived > 0
byteBuffer = New Byte(1024) {}
bytesReceived = handler.Receive(byteBuffer)
If bytesReceived > 0 Then
ReDim Preserve m_data(bytesTotalReceived + bytesReceived - 1)
Array.Copy(byteBuffer, 0, m_data, bytesTotalReceived,
bytesReceived)
bytesTotalReceived = bytesTotalReceived + bytesReceived
End If
End While
Nov 20 '05 #1
2 2705
In article <7a**************************@posting.google.com >, Qindong Zhang wrote:
My socket application blocked at socket.receiver() after received all
information from sender. Should socket.Receive() return 0 after no
more data available? Note: My socket object was not close on both
client/server side. My cached for further use.

While bytesReceived > 0
byteBuffer = New Byte(1024) {}
bytesReceived = handler.Receive(byteBuffer)
If bytesReceived > 0 Then
ReDim Preserve m_data(bytesTotalReceived + bytesReceived - 1)
Array.Copy(byteBuffer, 0, m_data, bytesTotalReceived,
bytesReceived)
bytesTotalReceived = bytesTotalReceived + bytesReceived
End If
End While


Socket.Receive is a blocking call. If there is no data in the pipe, it
will wait. It returns 0 if the remote endpoint shuts down.

Basically, you need to have a transmision protocol defined between the
client and server so that you know how much data to read. Commonly, if
the data is varying lengths the stream will be delimited with a control
sequence - such as CR+LF - but that is not a requirement of TCP, that is
an application layer function. Then when you read from the socket, you can
check for the presence of this sequence to determine if you have reached
the end of the current transmission.

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #2
if i need to break my blocked receive call to do a send (which is an
event for button click) and then go back again on a blocked receive,
how would i do that ?
thanks
Tom Shelton wrote:
In article <7a**************************@posting.google.com >, Qindong Zhang wrote:
My socket application blocked at socket.receiver() after received all information from sender. Should socket.Receive() return 0 after no
more data available? Note: My socket object was not close on both
client/server side. My cached for further use.

While bytesReceived > 0
byteBuffer = New Byte(1024) {}
bytesReceived = handler.Receive(byteBuffer)
If bytesReceived > 0 Then
ReDim Preserve m_data(bytesTotalReceived + bytesReceived - 1) Array.Copy(byteBuffer, 0, m_data, bytesTotalReceived,
bytesReceived)
bytesTotalReceived = bytesTotalReceived + bytesReceived
End If
End While


Socket.Receive is a blocking call. If there is no data in the pipe,

it will wait. It returns 0 if the remote endpoint shuts down.

Basically, you need to have a transmision protocol defined between the client and server so that you know how much data to read. Commonly, if the data is varying lengths the stream will be delimited with a control sequence - such as CR+LF - but that is not a requirement of TCP, that is an application layer function. Then when you read from the socket, you can check for the presence of this sequence to determine if you have reached the end of the current transmission.

--
Tom Shelton
MVP [Visual Basic]


Nov 21 '05 #3

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

Similar topics

6
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: ...
5
by: Terry | last post by:
It's my understanding of UDP sockets that if there is a thread blocked on a "recvFrom()" call and other thread sends a UDP packet to some address, that if the machine on the other end isn't up,...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
5
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...
1
by: Laura T. | last post by:
Hi, I've this kind a program, using sockets to communicate with the clients. One of the clients can be a web browser (like IE). When using IE as a client, the transmission blocks completely, and...
3
by: Eric Marthinsen | last post by:
Hello- I'm trying to create a console app that will accept an incoming HTTP request and output the information of the request to the console. The code is pretty simple - here's what it looks...
9
by: semedao | last post by:
Hi, I am using sync and async operations on the same socket. generally I want the socket to wait on BeginReceive and to not block the object thread. but in some cases I want to stop the...
14
by: =?Utf-8?B?TWlrZVo=?= | last post by:
I have a sync socket application. The client is blocked with Socket.Receive(...) in a thread, another thread calls Socket.Close(). This unblock the blocked thread. But the socket server is still...
3
by: Joe Blauth | last post by:
Hi all, I am currently working on a small application that sends messages from a client to a server and receives messages in return. Basically the functionality is made with sockets which is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.