473,586 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Sockets interesting problem

Hi,
I have been programmin in C# for quite some time now and recently got
into sockets programming in C# though i have done it in C++ on
windows/linux . I have an interesting problem at hand .

I am porting a C++ tunnel library into C# . It has 2 functions

WriteOut: I make a header and send it then send the actual data to the
server and it calls Write function

DoReceive: I try consuming data on socket by calling Consume function
(code below) from the server and then look for header signature in
data , if i find it i construct my header and then look for the buffer
in the rest of the data .

Now the test application makes a thread for receiving data that is in
a loop calling DoReceive and a little sleep after that and the main
app thread starts sending data buffers using WriteOut .

The problem is that if i dont start the receive thread , send keeps
working fine and never get stucks forever ... but when the receive
thread is also started the m_Sock.Send stucks forever after a variable
number of packets send, it never returns neither it throws an
exception (strange it is i know) , i have it in try catch block and
believe me no exception is fired even after a long time. Receive just
receives a couple of packets before the send gets stuck .

And if i run two instances of application where one is sending and the
other is just receving data back from the server ...receive doesnt
receive ANYTHING

I dont know whats wrong with this C# sockets . Please help, code below
for reference
public bool Write(byte []buffer, int Size)

try
{
size = m_Sock.Send(buf fer,0,Size,Sock etFlags.None);
}
catch(Exception e)
{
MainForm.writer .WriteLine(e.Me ssage);
MainForm.writer .Flush();
}
public bool Consume(int nBytes )

ArrayList readList = new ArrayList();
while (!m_bClosing)
{
readList.Add(m_ Sock);

Socket.Select(r eadList,null,nu ll,200);

if(readList.Cou nt == 0) return true;

if(readList.Cou nt > 0)
{
int Got = m_Sock.ReceiveC ircleBuffer,Cir cleWrite,Max,So cketFlags.None) ;

if (Got < 1) return false;
Not complete code but just relevant portions.
Nov 16 '05 #1
0 1259

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

Similar topics

4
15611
by: Dr.Kadzija | last post by:
i have a client-server application. client and server should communicate via tcp sockets. ok, so i use Sockets, PrintWriter and BufferedReader. the problem is that: both client and server will send each other multiple lines (using PrintWriter.println()) at a time, and i don't know how many lines each of them will send. this wouldn't be a...
1
3776
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for pending connections every 500ms. I also have a vb6 application that uses the WinSock control at the other end of the communication tunel. I have to...
15
2182
by: mrpolitics | last post by:
So I'm working with PureIRCD (http://sourceforge.net/projects/pure-ircd) and everything was fine untill yesterday when the server crashed. So I did a cold restart and staretd the server back up now it's throwing this stream of errors right away. DOes anyone have any idea what they mean. I havn't changed the source at all since it was...
3
11573
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.ReceiveFrom(Byte buffer, Int32 offset, Int32 s
14
11880
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was doing something was really inefficient and could reduce 10 lines of code with 2, etc. For reading, I am using a TcpClient and I call ...
0
1439
by: rossabri | last post by:
This topic has been addressed in limited detail in other threads: "sockets don't play nice with new style classes :(" May 14 2005. http://groups.google.com/group/comp.lang.python/browse_thread/thread/76d27388b0d286fa/c9849013e37c995b "Subclassing socket" Dec 20 2005 - Jan 14 2006....
5
1822
by: Navin Mishra | last post by:
Hi, In load test of our .NET 2.0 socket application on Win2003 server, we are seeing sometimes WSEWOULDBLOCK error when sending data to clients. We are using synchronoous scokets with SendTimout of 2 secs. Is it normal ? Thanks in advance and regards Navin
0
8200
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. ...
0
8215
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...
1
5710
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...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
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...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
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...

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.