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

Exception:System.Net.Sockets.SocketException:

Hi all.

I have a problem with TcpClient ... I am conneting to a server with
TcpClient and returning the answer through a webservice.

It actully all works fine. BUT if I make a lot of (re)connection
(hitting the submit button) then I start to recieve a an error:

IOException:System.IO.IOException: Der kunne ikke læses data fra
transportforbindelsen (LPF: could not read data from the transport
connection): An existing connection was forcibly closed by the remote
host ---System.Net.Sockets.SocketException: En eksisterende
forbindelse blev tvangsafbrudt af en ekstern vært ved
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32
size, SocketFlags socketFlags) ved
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size) --- Slut på staksporing af indre undtagelser --- ved
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size) ved SocketApplication.TrafikSocket.Connect(String server,
Int32 port, String message) i c:\www\WebSocket\App_Code
\TrafikSocket.cs:linje 63
It starts failing in the line: Int32 bytes = stream.Read(data, 0,
data.Length); The program that I am sending the reqeust to has to be
restartet before the system answers again. Nothing in that program is
hanging and the Port is listining...

Any one has any idea where to debug that problem?! Currently I have no
idea :-(
public string Connect(String server, Int32 port, String
message)
{

// variablerne er benyttes
TcpClient client = null;
NetworkStream stream = null;

try
{

client = new TcpClient(server, port);

// Translate the passed message into ASCII and store
it as a Byte array.
Byte[] data =
System.Text.Encoding.UTF8.GetBytes(message);

// Get a client stream for reading and writing.
// Stream stream = client.GetStream();
stream = client.GetStream();

// String to store the response UTF7 representation.
String responseData = String.Empty;

// Send the message to the connected TcpServer.
if (stream.CanWrite)
{
stream.Write(data, 0, data.Length);

// Receive the TcpServer.response.
// Buffer to store the response bytes.
data = new Byte[256];
// Read the first batch of the TcpServer response
bytes.
if (stream.CanRead)
{
Int32 bytes = stream.Read(data, 0,
data.Length);
responseData =
System.Text.Encoding.UTF7.GetString(data, 0, bytes);
}
}

// Close everything.
stream.Close();
client.Close();

return responseData;
}
....

Sep 14 '07 #1
1 4415

On Sep 14, 12:07 pm, larspe...@faerge.dk wrote:
The program that I am sending the reqeust to has to be restartet before
the system answers again.
This suggests the problem is in the server, and not your client. I
assume restarting the client doesn't change anything?

(Disclaimer: I didn't look at your code.)

Sep 14 '07 #2

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

Similar topics

1
by: DelboyJay | last post by:
I have found a strange resource problem, but luckily I have also found the solution which was not obvious from the runtime exception. I really think that the compiler should pick up this problem...
3
by: nick | last post by:
The program runs well on Local harddisk. But it always popup the exception if I run it on Netware mapping disk. After debugger say there is no source code on the exception. Also the following error...
1
by: Ripul Handa | last post by:
Hi We are running IIS 5.0 cluster with cisco local director. We are running a website on 2 webservers and I have been observing that from past few days we have are getting this error message of...
3
by: James | last post by:
Hi guys Do you ever get the exception in Managed C++? How can I know which file or dll is missed?
3
by: NormD | last post by:
An exception 'System.ExecutionEngineException' has occurred in servername I have deployed a windows application on a server; I'm running the same on my pc using...
1
by: Coder | last post by:
Hi My C# .Net Application runs fine on local machine, it s also runs fine on windows 2003 server installed machine, but on my client machine, when I am trying to run my application from mapped...
0
by: Sutabi | last post by:
I'm trying to compile a "Release" build of a project, and in debug more it compiles and runs fine. In release mode it builds, but does not run and returns this exception. I have no idea what this...
1
by: umeshatpromact | last post by:
Hello!, I got following exception when using COM component for EXCEL object in ASP .Net. I have added reference of "Microsoft.Office.Interop.Excel.dll" I deployed an application on local...
1
by: Abstract Labs | last post by:
We have recently deployed our application with the addition of AJAX.net for the last two weeks we have been suffering deadlock issues with the application pool. We are in a farmed environment and...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.