473,387 Members | 3,821 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,387 software developers and data experts.

Remoting and concurrent socket connections

Hello

Having been trying to find the root of this problem for several days I
now hope that you can help me.

I'm implementing a distributed file system - consisting of, at the
moment, a testing client (C), a http-server (H) and a file server (F) -
with the following setup:

H acts as an external interface to F, that is any given C connect to
one H in order to access files at F. The communication between H and F
uses remoting, ie. F registers a FileServerObject which interfaces the
local file system which acts as the file storage. Testing H and F alone
works fine.
The communication between C and H uses regular sockets and uses the
HTTP1.1 protocol for communication. These two work fine together.

The problem then is when I try to test the system as a whole. When
trying to authorize (using a custom implemented certificate driven
authorization protocol) H suddenly starts to act weird when reading
data from the NetworkStream based on the socket connected to C. It
simply stops reading data at the stream at various points in the
authorization process.

Somehow the remoting setup effects the communication with the clients.
Sometimes all works perfectly, other times certificates or encrypted
secrets are never read at H. How can this be?
No exceptions are ever throws, the NetworkStram.Read(...) simply blocks
as no data are available. Have the remoting framework somehow consumed
the data?

I've included the method that reads from the NetworkStream for you to
see.

If you have any questions that would clarify my problem, please feel
free to ask.

private byte[] ReadPut()
{
//Validate for content-length header
if (!_lastRequest.Headers.ContainsKey("Content-Length"))
{
WriteHttpResponse(HttpResponseCodes.BadRequest, "Content-Length
header missing");
return null;
}
else
{
int contentLength =
int.Parse(_lastRequest.Headers["Content-Length"]);
//Log("Content-Length: " + contentLength);
byte[] fullContent = new byte[contentLength];

int readBytesTotal = 0;
while (readBytesTotal < contentLength)
{
int readBytes = _networkStream.Read(fullContent,
readBytesTotal, (contentLength - readBytesTotal < 1024 ? contentLength
- readBytesTotal : 1024));
readBytesTotal += readBytes;

if (readBytes == 0)
break;
}
if (readBytesTotal == 0)
return null;
else
{

//
Console.WriteLine(ASCIIEncoding.Default.GetString( fullContent));
return fullContent;
}
}
}

Best regards,
Thomas René Sidor

Sep 24 '06 #1
1 1932
Ok, apparently the code does not work even if i disable the remoting
part at this moment. Communication between the client and http server
stops at random, although some data always get send. I.e. I send a http
request with some headers and a body - the headers are read using a
StreamReader created on top of the NetworkStream - this always works
without problems. The problem occurs when reading the body (using the
previously posted method) from the NetworkStream.

Any suggestions as to how this can be?

The client is implemented using HttpWebReqeust / HttpWebResponse and
the server accepts connections using a TcpListener which accepts
TcpClients.

For the purpose of development I have the client start the http server
and file server processes - could this influence on the
networkstream?

Below is the code that accepts new incoming connections.

private void ListeningLoop()
{
Log("Starting HttpServer");
bool exitLoop = false;

TcpListener listener = new TcpListener(new
IPEndPoint(IPAddress.Parse("127.0.0.1"), _port));
// Registering TcpChannel for remoting
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel, true);

Log("HttpServer up and running. Listening on port " + _port);
listener.Start();
// Listening for incomming connection to the HttpServer
while (true)
{
// If we for some reason need to stop the server, neat cleanup
can be handled here
if (exitLoop)
{
Cleanup();
break;
}
try
{
TcpClient client = listener.AcceptTcpClient();
ConnectionHandlerInstance connectionHandler = new
ConnectionHandlerInstance(client);
Thread connectionHandlerTread = new Thread(new
ThreadStart(connectionHandler.HandleConnection));
connectionHandlerTread.Start();
}
catch (Exception)
{
//Log(e.ToString());
Log("Failed to accept connection");
}
}
}
I would appreciate any feedback.

Best reagards,
Thomas René Sidor

Sep 25 '06 #2

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

Similar topics

1
by: boxim | last post by:
Hi all, Just some queries re: remoting. I've been asked to write an app where many people may simultaneously open it and share information. Sounds simple enough, and normally I'd use a...
2
by: Steven Blair | last post by:
Hi, I have Server application which handles a single conenction froma client. I want this program to accept concurrent connections. Anyone help me out ? I am using a TcpListener object. I...
0
by: Ken Foster | last post by:
I built some remote services, a couple singletons and one single call. On the client side I thought I'd save on connection latency by caching the remote connection in a shared variable. Create it...
1
by: David Krmpotic | last post by:
Hi All! I have a .NET remoting Client-Server application with Server Activated Objects only.. something is worrying me.. sometimes (rarely), I can't connect to the server although it is...
6
by: AMDRIT | last post by:
Hello folks, I appologize for the cross post, but I really need an answer on this: I do not think that I am seeing the whole picture here. I would like to create a windows service and a...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
6
by: roblugt | last post by:
I have what I imagine is a well-known .Net networking problem, but even though I've Googled for some time I've not yet come across a thread where this has been fully explained... There is a...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
0
by: Kristian Reukauff | last post by:
Hi I have a problem with the .Net-Securty-Functions. I've got a client and a server. When I try to register a channel at the server with this line: ChannelServices.RegisterChannel(chan, false);...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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,...
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.