473,796 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p);
String szIPSelected = m_strServerUri;
String szPort = "800";
int alPort = System.Convert. ToInt16 (szPort, 10);
System.Net.IPAd dress remoteIPAddress = System.Net.IPAd dress.Parse(szI PSelected);
System.Net.IPEn dPoint remoteEndPoint = new
System.Net.IPEn dPoint(remoteIP Address, alPort);
m_socClient.Con nect(remoteEndP oint);
string requestHeader = "POST / HTTP/1.1\r\nContent-Type: " +
"applicatio n/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.Sen d (bytesHeader , 0, bytesHeader .Length,
SocketFlags.Non e);

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

byte[] response = new byte[4000];
// Doesn't block until read returns.
m_socClient.Blo cking = true;
nBytes = 0;
//*************** PROBLEM HERE ************////
while ( nBytes > 0 )
{
nBytes = m_socClient.Rec eive (response, response.Length , 0);
}
//*************** *************** **************
Console.WriteLi ne ("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 883

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

Similar topics

4
2432
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 the prompt. I have to push Ctrl-C in order to have it exit completely. The GUI is closed though. This is a piece of code from the main class that connects to the server and starts a thread that handles the connection: =======================...
9
4304
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 some packets in response to the programs first message, but when I receive a response back, it's the last packet I sent. After that packet, I receive the packet I really wanted. This only happens when I connect with local host. I tried...
3
2418
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 to have a regex that will capture the start, middle and end of this file based on the tags. The problem is that the end tag may not always be present, and the content (xxxxxxx in this case) may contain carriage returns.
0
3588
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 supposed to do the following: monitor ALL INCOMING TCP traffic on the local computer, and save certain parts of it as files - not log files though, but actual files that are sent to the computer as part of http or ftp. Basically if a user browse a page...
1
4170
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 52927 0 10.138.156.41:8901 150.169.7.110:4493 CLOSE_WAIT tcp 52927 0 10.138.156.41:8901 150.169.7.110:4492 CLOSE_WAIT tcp 52927 0 10.138.156.41:8901 150.169.7.110:4495 CLOSE_WAIT tcp 52927 ...
0
9531
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10237
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10187
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
10018
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...
1
7553
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
5446
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
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.