473,405 Members | 2,294 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,405 software developers and data experts.

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("localhost",8888);

NetworkStream networkStream ;

networkStream = myclient.GetStream();

StreamWriter streamWriter ;

streamWriter = new StreamWriter(networkStream);

string strData = "";

strData += "0\0";

streamWriter.WriteLine(strData);

streamWriter.Flush();

streamWriter.Close() ;

networkStream.Close();

myclient.Close();

int i23 = 23+ 23;

}
here is my server:
using System;

using System.Net.Sockets;

using System.IO ;

public class Echoserver

{

public static void Main()

{

TcpListener tcpListener = new TcpListener(8888);

tcpListener.Start();

Console.WriteLine("Server Started") ;

while(true)

{

Socket socketForClient = tcpListener.AcceptSocket();

try

{

if(socketForClient.Connected)

{

Console.WriteLine("Client connected");

NetworkStream networkStream = new NetworkStream(socketForClient);

StreamReader streamReader = new StreamReader(networkStream);

string line = streamReader.ReadLine();

Console.WriteLine("Read:" +line);

}

socketForClient.Close();

Console.WriteLine("Client disconnected");

}

catch(Exception e)

{

Console.WriteLine(e.ToString()) ;

}

}

}

}


Jul 21 '05 #1
1 3754
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("localhost",8888);

NetworkStream networkStream ;

networkStream = myclient.GetStream();

StreamWriter streamWriter ;

streamWriter = new StreamWriter(networkStream);

string strData = "";

strData += "0\0";

streamWriter.WriteLine(strData);

streamWriter.Flush();

streamWriter.Close() ;

networkStream.Close();

myclient.Close();

int i23 = 23+ 23;

}
here is my server:
using System;

using System.Net.Sockets;

using System.IO ;

public class Echoserver

{

public static void Main()

{

TcpListener tcpListener = new TcpListener(8888);

tcpListener.Start();

Console.WriteLine("Server Started") ;

while(true)

{

Socket socketForClient = tcpListener.AcceptSocket();

try

{

if(socketForClient.Connected)

{

Console.WriteLine("Client connected");

NetworkStream networkStream = new NetworkStream(socketForClient);

StreamReader streamReader = new StreamReader(networkStream);

string line = streamReader.ReadLine();

Console.WriteLine("Read:" +line);

}

socketForClient.Close();

Console.WriteLine("Client disconnected");

}

catch(Exception e)

{

Console.WriteLine(e.ToString()) ;

}

}

}

}


Jul 21 '05 #2

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

Similar topics

2
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...
1
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...
3
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....
1
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...
8
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...
1
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...
0
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
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...
1
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...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.