Re: socket questions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

Are you sure all your variables are local to each thread?
Cause I assume you are using threads when dealing with more than one
connection no?

This is part of the code I use :

Thread listenerThread;

Queue connectionQueue= null;

protected void ListenerMethod()
{
Thread workingthread;

Queue unsyncq = new Queue();
connectionQueue = Queue.Synchronized( unsyncq);

TcpClient socket;
TcpListener listener = new TcpListener( Config.Port);
listener.Start();
while( true)
{
socket = listener.AcceptTcpClient();
connectionQueue.Enqueue( socket);

workingthread = new Thread( new ThreadStart( TheConnectionHandler));
workingthread.Start();
}
}

public void TheConnectionHandler()
{

TcpClient socket= (TcpClient)connectionQueue.Dequeue();

}


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"coloradowebdev" <coloradowebdev@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B270D9E8-781C-4198-8AFC-3F44D6FB2A14@xxxxxxxxxxxxxxxx
> i've actually tried a number of different approaches, which i will try to
> summarize below...
>
> synchronous: this works fine for one transaction, but sending any more
> than
> one does not (send while waiting for a response from a previous
> transaction
> causes the read to fail (return nothing))
>
> [Send Synchronous, then]
> int i = sock.Receive(buffer, 0, sock.Available, SocketFlags.None);
> byte[] response = new byte[i];
> Array.Copy(buffer,0,response,0,i);
> //Console.WriteLine("Out of Transact : " +
> Comcast.Common.Encoding.HexEncoder.ToString(response));
> return response;
>
> asynchronous:
>
> i stripped out the last version of asynchronous reading. basically, it
> was
> sending synchronously while listening asynchronously. when something was
> received, if it contained the special terminating character, it would
> raise
> an event with the server response as the event argument. the code was a
> combination of asynchronous samples from the MSDN site and other
> references
> on the net that used BeginReceive.
>
> I know it can't be THIS hard. I'm adding TCP functionality to the
> application that was previously all serial based. the logic in the serial
> based one was check if the port is available, if it is send, lock the port
> until something is received, return the response, close the port. i'm not
> a
> big TCP/IP person, but i figure there should be some information out there
> that would put me on the right path.
>
> "Ignacio Machin ( .NET/ C# MVP )" wrote:
>
>> Hi,
>>
>>
>> post the code you are using to communicate with the remote TCP server,
>> are
>> you using multithread? each thread generating a connection ?
>>
>> cheers,
>>
>> --
>> Ignacio Machin,
>> ignacio.machin AT dot.state.fl.us
>> Florida Department Of Transportation
>>
>>
>> "coloradowebdev" <coloradowebdev@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
>> message
>> news:757A4761-716D-49B0-8624-86DBF58048EF@xxxxxxxxxxxxxxxx
>> >i am working on basically a proxy server that handles requests via
>> >remoting
>> > from clients and executes transactions against a third-party server via
>> > TCP.
>> >
>> > the remoting site works like a champ. my problem is executing the
>> > transactions against the remote server and returning the response to
>> > the
>> > remoting client. i can open the socket fine and, if i am executing one
>> > transaction at a time, everything works great. it's when my proxy
>> > server
>> > tries to execute multiple transactions, i'm missing something on the
>> > socket
>> > end. i have tried both synchronous and asynchronous, but it just seems
>> > that
>> > the socket stops listening after one response is received and ignores
>> > the
>> > other pending transactions.
>> >
>> > i've tried a number of different approaches, and posted messages on the
>> > forums.microsoft board. i have to believe that someone, somewhere has
>> > build
>> > a transaction-type system like this one. but most of the samples and
>> > advice
>> > that i have received have all pointed to a server listening for and
>> > accepting
>> > multiple clients, instead of one application connecting to a remote
>> > server
>> > with a number of concurrent (client) connections.
>> >
>> > if anyone has any useful links or suggestions, it would be appreciated.
>> > thanks in advance.
>>
>>
>>


.



Relevant Pages

  • Re: Socket Exception
    ... In this case the server most likely rejected your ... connection. ... Each command is a new socket connection that is opened and closed ... /// Required designer variable. ...
    (microsoft.public.win32.programmer.networks)
  • Re: ASP.NET 2.0 - a newbie question
    ... Is there some experienced ASP.NET 2.0 developer, ... server that comes bundled Microsoft VWDE. ... A connection attempt failed because the ... connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Is yahoo being hijacked?
    ... I get no server response when query ... > Connection: close ...
    (misc.invest.stocks)
  • Re: Is yahoo being hijacked?
    ... I get no server response when query ... > Connection: close ...
    (misc.invest.stocks)
  • Is yahoo being hijacked?
    ... I get no server response when query ... The server returned the following response headers: ... Connection: close ...
    (misc.invest.stocks)