Re: socket questions

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



Hi,

You are right about the server side of the communication, sorry for that
mistake. You can use it in case you need it.


Each connection use theirs own particular socket instance , even if they
are connecting to the same remote host/port



in any case multithreading the client is the only possible way of doing
this.

> where i send something and wait for a response,

This depends of the protocol the server is using, do you know how it
handles the communication?

> but i need to be able to do
> that with 50 simultaneous calls.
>

Ok do this, get rid of the remoting part and just try your tcp code as if
you were receiving several remoting requests.

cheers,

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



"coloradowebdev" <coloradowebdev@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C339FA8E-B75B-4DE4-9B57-77B7D8BA01AC@xxxxxxxxxxxxxxxx
>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.
>> >>
>> >>
>> >>
>>
>>
>>


.



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)