473,387 Members | 1,575 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.

Problem in receiving data from socket.

SK
Hi,

I am trying to send/receive data from a socket.
The call to receive does not block .
If I use sleep between send and receive things are ok.
Here is the code -

Socket m_socClient;
//create a new client socket ...
m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
String szIPSelected = m_strServerUri;
String szPort = "800";
int alPort = System.Convert.ToInt16 (szPort, 10);
System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint remoteEndPoint = new
System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socClient.Connect(remoteEndPoint);
string requestHeader = "POST / HTTP/1.1\r\nContent-Type: " +
"application/vnd.\r\n" +
"Content-Length: 1000" +
"\r\nConnection: Close\r\n\r\n";
Byte[] bytesHeader = Encoding.ASCII.GetBytes (requestHeader);

// Blocks until send returns.
int nBytes = 0;
nBytes = m_socClient.Send (bytesHeader , 0, bytesHeader .Length,
SocketFlags.None);

Console.WriteLine ("No. of bytes sent" + nBytes);

byte[] response = new byte[4000];
// Doesn't block until read returns.
m_socClient.Blocking = true;
nBytes = 0;
//*************** PROBLEM HERE ************////
while ( nBytes > 0 )
{
nBytes = m_socClient.Receive (response, response.Length, 0);
}
//********************************************
Console.WriteLine ("No. of bytes recvd." + nBytes);

Always nBytes is returning as 0. If I use sleep between send and receive things
work but that's not the proper way.
What is going wrong?

Best regards,
SK
Nov 15 '05 #1
0 867

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

Similar topics

4
by: flupke | last post by:
Hi, I have a gui (made in wxPython) that enables a user to connect to a server and issue some commands. The problem occurs when i try to disconnect the client. It exits but it doesn't return to...
9
by: darthghandi | last post by:
I am trying to create a server application using asynchronous sockets. I run into a problem when I try to connect to my server using a non-.net program. I can establish the connection, and send...
3
by: =?Utf-8?B?c2JwYXJzb25z?= | last post by:
I have a scenario where a string is sent in chunks to my app. I need to be able to identify certain tags in this partial string as it arrives. eg <DALFile>xxxxxxxxx</DALFile> I need to be able...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
1
by: tvnaidu | last post by:
I have receiver socket on 8901 and sender socket on 9801, I can see receiver quue going up and state "CLOSE_WAIT" and sender Connection established, but receiver side an error, any idea?. tcp ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.