473,386 Members | 1,745 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,386 software developers and data experts.

roburst network programming, tcpClient.Client.SetSocketOption(SocketOptionLevel .Tcp , SocketOptionName.KeepAlive , 1);

Hi,

I use

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

while(true)
{
TcpClient client = myListener.AcceptTcpClient();
....
}
Client:
tcpClient = new TcpClient(host,port);
stream =tcpClient.GetStream();
....
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.InvalidOperationException: 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.SetSocketOption(), which can set SocketOptionName.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.Client.SetSocketOption(SocketOptionLevel .Tcp ,
SocketOptionName.KeepAlive , 1);

Thanks a lot!
Ryan

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

chanmm

"Ryan Liu" <ad********@online.sh.cnwrote in message
news:un**************@TK2MSFTNGP04.phx.gbl...
Hi,

I use

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

while(true)
{
TcpClient client = myListener.AcceptTcpClient();
....
}
Client:
tcpClient = new TcpClient(host,port);
stream =tcpClient.GetStream();
....
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.InvalidOperationException: 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.SetSocketOption(), which can set SocketOptionName.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.Client.SetSocketOption(SocketOptionLevel .Tcp ,
SocketOptionName.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.InvalidOperationException: 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.SetSocketOption(), which can set SocketOptionName.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.at????
news:e1****************@TK2MSFTNGP03.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.InvalidOperationException: 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.SetSocketOption(), which can set SocketOptionName.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
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...
0
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...
13
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...
0
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...
2
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...
1
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...
4
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 {...
0
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...
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...
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.