Re: socket questions
- From: "coloradowebdev" <coloradowebdev@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 6 Dec 2005 07:55:03 -0800
i tried separate threads, as well. the code you posted includes a
tcplistener, which is the server side, right? my proxy server (which is
actually a client at this point) will be the one initiating the conversation
with the remote server, not listening for clients to connect, unless i am
missing something.
i was thinking about it (again) last night, and i think my biggest problem
is that i am trying to make something serial that isn't. with my COM ports,
one port is open, handles the transaction, and is closed. with the socket,
multiple connections use the same socket so it isn't as easy as listening to
one channel for a response. the responses seem to be stepping one each other
when responses are received. i think what i want is a synchronous socket call
where i send something and wait for a response, but i need to be able to do
that with 50 simultaneous calls.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
> 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.
> >>
> >>
> >>
>
>
>
.
- Follow-Ups:
- Re: socket questions
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: socket questions
- References:
- Re: socket questions
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: socket questions
- From: coloradowebdev
- Re: socket questions
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: socket questions
- Prev by Date: Re: XSLT and Excel
- Next by Date: Re: ExecuteReader
- Previous by thread: Re: socket questions
- Next by thread: Re: socket questions
- Index(es):
Relevant Pages
|