473,725 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address"


after opening socket, sending data then closing socket 3000 times i get
"Only one usage of each socket address"

what am i doing wrong? is there some thing else i need to do to free up the
socket after i send data into it?

I simply want to open socket, send data, close socket and have the server
just handle one client thread to recieve connection, recieve data, and close
socket
here is my client:

for(int i=0;i<10000;i++ )

{

TcpClient myclient;

myclient = new TcpClient("loca lhost",8888);

NetworkStream networkStream ;

networkStream = myclient.GetStr eam();

StreamWriter streamWriter ;

streamWriter = new StreamWriter(ne tworkStream);

string strData = "";

strData += "0\0";

streamWriter.Wr iteLine(strData );

streamWriter.Fl ush();

streamWriter.Cl ose() ;

networkStream.C lose();

myclient.Close( );

int i23 = 23+ 23;

}
here is my server:
using System;

using System.Net.Sock ets;

using System.IO ;

public class Echoserver

{

public static void Main()

{

TcpListener tcpListener = new TcpListener(888 8);

tcpListener.Sta rt();

Console.WriteLi ne("Server Started") ;

while(true)

{

Socket socketForClient = tcpListener.Acc eptSocket();

try

{

if(socketForCli ent.Connected)

{

Console.WriteLi ne("Client connected");

NetworkStream networkStream = new NetworkStream(s ocketForClient) ;

StreamReader streamReader = new StreamReader(ne tworkStream);

string line = streamReader.Re adLine();

Console.WriteLi ne("Read:" +line);

}

socketForClient .Close();

Console.WriteLi ne("Client disconnected");

}

catch(Exception e)

{

Console.WriteLi ne(e.ToString() ) ;

}

}

}

}


Jul 21 '05 #1
1 3792
Hi Daniel,

I have enocountered the same problem as you. My client application has a
public fuction which does "connect -> send -> close" operation to a remote
listening application. At first, everything seems fine, we even succeeded
sending 10,000 calls from the client application. From the netstat, it shows
that the client ports get recycled very neatly.

However, when we started having multiple client applications connecting to
the same server, problem started. Error message "only one usage of each
socket address" start to appear.

It has been a month since you posted. Is it solved?

Rdgs,
Vin

"Daniel" wrote:

after opening socket, sending data then closing socket 3000 times i get
"Only one usage of each socket address"

what am i doing wrong? is there some thing else i need to do to free up the
socket after i send data into it?

I simply want to open socket, send data, close socket and have the server
just handle one client thread to recieve connection, recieve data, and close
socket
here is my client:

for(int i=0;i<10000;i++ )

{

TcpClient myclient;

myclient = new TcpClient("loca lhost",8888);

NetworkStream networkStream ;

networkStream = myclient.GetStr eam();

StreamWriter streamWriter ;

streamWriter = new StreamWriter(ne tworkStream);

string strData = "";

strData += "0\0";

streamWriter.Wr iteLine(strData );

streamWriter.Fl ush();

streamWriter.Cl ose() ;

networkStream.C lose();

myclient.Close( );

int i23 = 23+ 23;

}
here is my server:
using System;

using System.Net.Sock ets;

using System.IO ;

public class Echoserver

{

public static void Main()

{

TcpListener tcpListener = new TcpListener(888 8);

tcpListener.Sta rt();

Console.WriteLi ne("Server Started") ;

while(true)

{

Socket socketForClient = tcpListener.Acc eptSocket();

try

{

if(socketForCli ent.Connected)

{

Console.WriteLi ne("Client connected");

NetworkStream networkStream = new NetworkStream(s ocketForClient) ;

StreamReader streamReader = new StreamReader(ne tworkStream);

string line = streamReader.Re adLine();

Console.WriteLi ne("Read:" +line);

}

socketForClient .Close();

Console.WriteLi ne("Client disconnected");

}

catch(Exception e)

{

Console.WriteLi ne(e.ToString() ) ;

}

}

}

}


Jul 21 '05 #2

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

Similar topics

2
3088
by: David Konerding | last post by:
Hello, I have written an app which opens a TCP connection to a server and uses a protocol to communicate with it. Specifically, I've written a python IMD client for the molecular dynamics application 'NAMD' (do searches for IMD and NAMD if you want to learn more). The protocol is very simple: both ends of the TCP connection can send messages to the other side at any time; when data is available on a read socket, a full packet (with known...
1
1509
by: Spam sucks | last post by:
hello, i create a logging xml file with dom that could have an unknown count of results now it is 0 to 7 but it could be i have 14 or 50 results how can you read this out with xsl, with php you would put it in an array or something but now i want to do it with xsl. in php it woul be like: foreach ($array as $key=>$value) {
3
2576
by: Vic | last post by:
Dear All, I have a database of laboratory records in Access 2000. There is one form which acts as an interface to input experimetal data. This form incorporates information from several tables. I have a flag (yes/no field) indicating whether a particular experiment (one record) is completed (ie all data belonging to that record is inputted and quality controlled). What I want is that when I change the flag to "yes" the particular record...
1
2684
by: PeteCresswell | last post by:
I'm working on a new report in an MS Access DB. The first anomaly was a message "This action will reset the current code in break mode." when the report was run. Seems TB something about my Detail1_Print(): if I answer "No" to the dialog the report just runs. If I answer "Yes", it pops a new dialog seemingly at every line. Code is below. The real zinger, however, started on Friday. When I run the report in question somehow MS...
8
21911
by: Grant Richard | last post by:
Using the TcpListener and TcpClient I created a program that just sends and receives a short string - over and over again. The program is fine until it gets to around 1500 to 1800 messages. At that time, I get a SocketException with the message "Only one usage of each socket address (protocol/network address/port) is normally permitted". This happen if you use localhost or between two distinct computers. And, for a period of time after the...
1
16453
by: Dr. J | last post by:
I have an application that opens a socket and connects to another application listening over a port. The problem I am encountering is that when the listening application is closed my application cannot detect it to take appropriate action. I am using "Connected" property of the Socket class, but it seems this property does not reflect the true state of the socket connection. Here is the code snippet. Basically, I am checking the...
0
1147
by: Adi Doron | last post by:
Dear Sir,Madam: How can i open multicast channel for: a) Sending Only b) Reciving Only Best Regards to all =================== Adi
2
2083
by: Mike Lerch | last post by:
I have data like this: Album Song Led Zeppelin I Good Times Bad Times Led Zeppelin I Babe I'm Gonna Leave You Led Zeppelin I You Shook Me Led Zeppelin I Dazed and Confused Led Zeppelin II Whole Lotta Love Led Zeppelin II The Lemon Song Led Zeppelin II Heartbreaker
1
320
by: Daniel | last post by:
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" what am i doing wrong? is there some thing else i need to do to free up the socket after i send data into it? I simply want to open socket, send data, close socket and have the server just handle one client thread to recieve connection, recieve data, and close socket
0
8889
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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
9401
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
9257
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
6702
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
6011
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();...
1
3228
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
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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.