473,769 Members | 6,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

roburst network programming, tcpClient.Clien t.SetSocketOpti on(SocketOption Level.Tcp , SocketOptionNam e.KeepAlive , 1);

Hi,

I use

Server:
Use an endless thread to lisiten to clients requests:

while(true)
{
TcpClient client = myListener.Acce ptTcpClient();
....
}
Client:
tcpClient = new TcpClient(host, port);
stream =tcpClient.GetS tream();
....
to build a client/server application, then both server and clients start
another endless thread to receive messages from each other, and use yet
other threads to send response to each other, or server pass messages from
one client to another.

Now about 60 workstations connect to one server, all in the same local LAN.

It is very ofter on server side log I see network problem for both read and
write to network stream, like:

Unable to write data to the transport connection.
An established connection was aborted by the software in your host machine.

Read System.InvalidO perationExcepti on: Operation not allowed on
non-connected sockets.

Can someone tell me what will cause the problem and how to write a roburst
network application?

I am using TcpClient, in SDK, I see there is a method

Socket.SetSocke tOption(), which can set SocketOptionNam e.KeepAlive

What does this mean, will this be helpful?

And do I have set this on both client and server side? And is this the right
way to use it:
tcpClient.Clien t.SetSocketOpti on(SocketOption Level.Tcp ,
SocketOptionNam e.KeepAlive , 1);

Thanks a lot!
Ryan

Jul 16 '06 #1
3 15532
Hope this will somehow help you but it is in VB.NET.
http://msdn.microsoft.com/library/de...et10232001.asp

chanmm

"Ryan Liu" <ad********@onl ine.sh.cnwrote in message
news:un******** ******@TK2MSFTN GP04.phx.gbl...
Hi,

I use

Server:
Use an endless thread to lisiten to clients requests:

while(true)
{
TcpClient client = myListener.Acce ptTcpClient();
....
}
Client:
tcpClient = new TcpClient(host, port);
stream =tcpClient.GetS tream();
....
to build a client/server application, then both server and clients start
another endless thread to receive messages from each other, and use yet
other threads to send response to each other, or server pass messages from
one client to another.

Now about 60 workstations connect to one server, all in the same local
LAN.

It is very ofter on server side log I see network problem for both read
and
write to network stream, like:

Unable to write data to the transport connection.
An established connection was aborted by the software in your host
machine.

Read System.InvalidO perationExcepti on: Operation not allowed on
non-connected sockets.

Can someone tell me what will cause the problem and how to write a roburst
network application?

I am using TcpClient, in SDK, I see there is a method

Socket.SetSocke tOption(), which can set SocketOptionNam e.KeepAlive

What does this mean, will this be helpful?

And do I have set this on both client and server side? And is this the
right
way to use it:
tcpClient.Clien t.SetSocketOpti on(SocketOption Level.Tcp ,
SocketOptionNam e.KeepAlive , 1);

Thanks a lot!
Ryan



Jul 16 '06 #2
Ryan Liu wrote:
It is very ofter on server side log I see network problem for both read and
write to network stream, like:

Unable to write data to the transport connection.
An established connection was aborted by the software in your host machine.

Read System.InvalidO perationExcepti on: Operation not allowed on
non-connected sockets.

Can someone tell me what will cause the problem and how to write a roburst
network application?

I am using TcpClient, in SDK, I see there is a method

Socket.SetSocke tOption(), which can set SocketOptionNam e.KeepAlive

What does this mean, will this be helpful?
I don't think KeepAlives will help you (see google). You are getting the
error because you are writing to a socket whose connection has been
closed (either intentionally or because of other reasons like network
problems or a crashed server).

When calling Socket.Receive you should 1) use a try/catch block around
it and 2) check the return value. A return value of 0 means that the
connection has been closed. You should not call Send on the socket after
it returned 0 bytes or after an exception. Close and destroy it.

btw - why not use async sockets instead of starting so many threads?

hth,
Max
Jul 16 '06 #3
Hi Markus,

Actually I have no problem with Listener, I have problem after the
connection is made. Then the server spawn one thread for each connected
client.

Actually there is not lot of threads. Only one thread for server to listen,
and one thread in server to receive data from each client and handle it.

When one client send message to server then server pass to another client,
it only involves one thread of the first client, but 2 network streams.

Thanks,
Ryan


"Markus Stoeger" <sp******@gmx.a t????
news:e1******** ********@TK2MSF TNGP03.phx.gbl. ..
Ryan Liu wrote:
It is very ofter on server side log I see network problem for both read
and
write to network stream, like:

Unable to write data to the transport connection.
An established connection was aborted by the software in your host
machine.

Read System.InvalidO perationExcepti on: Operation not allowed on
non-connected sockets.

Can someone tell me what will cause the problem and how to write a
roburst
network application?

I am using TcpClient, in SDK, I see there is a method

Socket.SetSocke tOption(), which can set SocketOptionNam e.KeepAlive

What does this mean, will this be helpful?

I don't think KeepAlives will help you (see google). You are getting the
error because you are writing to a socket whose connection has been
closed (either intentionally or because of other reasons like network
problems or a crashed server).

When calling Socket.Receive you should 1) use a try/catch block around
it and 2) check the return value. A return value of 0 means that the
connection has been closed. You should not call Send on the socket after
it returned 0 bytes or after an exception. Close and destroy it.

btw - why not use async sockets instead of starting so many threads?

hth,
Max

Jul 16 '06 #4

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

Similar topics

0
4437
by: Nathan Kerr | last post by:
I have been working with KB Article 812404 "HOW TO: Write Pluggable Protocol to Supprot FTP in Managed Classes by Using Visual Bassic.NET". I have modified the code to run on a Pocket PC. In the OpenControlConnection routine the following lines are being executed: m_DataSocket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
0
2850
by: Alphamacaroon | last post by:
All, I'm wondering if anyone can help me with a strange problem I'm having. First off, here's what I'm trying to do: I'm developing a UDP network application that should allow the end user to choose the network interface they want to send and receive UDP packets on. Simple enough. If the computer has a single network card and IP address this all works
13
31883
by: Sharon | last post by:
I'm using TcpClient and getting the Stream by: TcpClient tcpclnt = new TcpClient(); . . . Stream stm = tcpclnt.GetStream(); Now, when I'm trying to send a big buffer via stm.Write(...) I get an exception saying that the buffer is too big. I tried to set the tcpclnt.ReceiveBufferSize to the size of the buffer I"m trying to send, but the exception is still thrown, there is no transmit
0
1826
by: Eddy_w | last post by:
Hello, I try to ping from my mobile device with a wireless connection to my pc. I found the class clsping on the internet and it works perfect with application from pc to pc but when i use it from mobile device (win ce.net 4.2) to pc then it doesn't work anymore. I get on error on the following statement: Dim sckSocket As New System.Net.Sockets.Socket( _
2
5885
by: Wencheng Magiya | last post by:
By setting socket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.KeepAlive, 1 ) can tell the socket to use keep-alives. But anybody know how to set the timeout for the keep-alive without changing the registry? Best Regards, Wencheng Magiya
1
3118
by: Palaniappan | last post by:
HI, I need to set the timeout value for the sockets to handle network timeout in C#. I search for some API which is equivalent to that of the setSoTimeout() method in Java. Could any one of you please help me out? Thanks, Palaniappan.
4
1320
by: =?Utf-8?B?U2hhdW5P?= | last post by:
Hi, I set up an client to asynchronously receive data from it's connection. When i'm finished, i close the client using try { theClient.SetSocketOptionSocketOptionLevel.Socket,SocketOptionName.NoDelay,1); theClient.Shutdown(SocketShutdown.Both); theClient.Close(); theClient=null;
0
1402
by: Blog the Haggis | last post by:
Hi all, I've written a program which distributes binary data to a number of clients via TCP. The program runs perfectly unless one of the client programs hangs and then it freezes while waiting for the socket.send(Data) method to complete. I've tried all of these socket options to overcome this event: 'Set send timeout to 2 seconds:
0
3585
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...
0
10223
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
10051
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...
0
9866
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...
0
6675
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
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
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.