PC Review


Reply
Thread Tools Rate Thread

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

 
 
Daniel
Guest
Posts: n/a
 
      10th Feb 2005

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()) ;

}

}

}

}






 
Reply With Quote
 
 
 
 
=?Utf-8?B?Vmlueg==?=
Guest
Posts: n/a
 
      15th Mar 2005
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()) ;
>
> }
>
> }
>
> }
>
> }
>
>
>
>
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket.BeginSendTo and Socket.BeginSendFrom on a single Socket instancefrom multiple threads Jonas Hei Microsoft Dot NET Framework 9 5th Jul 2005 03:27 AM
Socket.BeginSendTo and Socket.BeginSendFrom on a single Socket instancefrom multiple threads Jonas Hei Microsoft C# .NET 2 22nd Jun 2005 12:10 PM
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" Daniel Microsoft Dot NET Framework 3 12th Feb 2005 02:53 PM
Network problem: "Could not start DB server: socket() failed for UDP socket" Antti Heiskanen Windows XP Networking 3 2nd Apr 2004 08:36 AM
Windows Socket error: Only one usage of each socket address ... Ron Reynolds Windows XP Performance 0 9th Aug 2003 03:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:20 AM.