473,395 Members | 2,151 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,395 software developers and data experts.

socket questions

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.
Dec 5 '05 #1
13 2617
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" <co************@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
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.

Dec 5 '05 #2
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(respon se));
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" <co************@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
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.


Dec 5 '05 #3
> i've actually tried a number of different approaches, which i will try to

synchronous or asynchronous doesnt matter, if the server is just programmed
to accept one connection than it'll just accpt one connection. It could take
multiple connections but maybe its not programmed that way. Have you
contacted the person who built the server? I think the way it used to work
serially, as you said, its working that same way using tcp and may not take
concurrent users/connections.
Just for your information, If I have to program a server to accept multiple
clients I do something like this:

while ( true )
{
TcpClient client = listening_socket.AcceptTcpClient(); //blocking call
// ... do processing with client, maybe open it in a new thread for
communicating, and come back to listening mode.

}

But it seems that they accept a connection, than communicates with the
client and when the client disconnects 'than' go into listening state
again, so to do one transaction at a time.

Ab.
http://joehacker.blogspot.com

"coloradowebdev" <co************@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com...
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(respon se));
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" <co************@discussions.microsoft.com> wrote in message news:75**********************************@microsof t.com...
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.


Dec 6 '05 #4
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" <co************@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com...
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(respon se));
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" <co************@discussions.microsoft.com> wrote in
message
news:75**********************************@microsof t.com...
>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.


Dec 6 '05 #5
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" <co************@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com...
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(respon se));
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" <co************@discussions.microsoft.com> wrote in
message
news:75**********************************@microsof t.com...
>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.


Dec 6 '05 #6
their server does accept multiple connections. i can watch my transactions
being processed on their server, its just that my client (when it tries to
send multiple transactions and wait for a response) doesn't handle the
responses properly (their server tries to send the responses, my client just
stops listening, or whatever).

"Abubakar" wrote:
i've actually tried a number of different approaches, which i will try to


synchronous or asynchronous doesnt matter, if the server is just programmed
to accept one connection than it'll just accpt one connection. It could take
multiple connections but maybe its not programmed that way. Have you
contacted the person who built the server? I think the way it used to work
serially, as you said, its working that same way using tcp and may not take
concurrent users/connections.
Just for your information, If I have to program a server to accept multiple
clients I do something like this:

while ( true )
{
TcpClient client = listening_socket.AcceptTcpClient(); //blocking call
// ... do processing with client, maybe open it in a new thread for
communicating, and come back to listening mode.

}

But it seems that they accept a connection, than communicates with the
client and when the client disconnects 'than' go into listening state
again, so to do one transaction at a time.

Ab.
http://joehacker.blogspot.com

"coloradowebdev" <co************@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com...
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(respon se));
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" <co************@discussions.microsoft.com> wrote in message news:75**********************************@microsof t.com...
>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.


Dec 6 '05 #7
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" <co************@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...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" <co************@discussions.microsoft.com> wrote in
message
news:B2**********************************@microsof t.com...
> 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(respon se));
> 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" <co************@discussions.microsoft.com> wrote in
>> message
>> news:75**********************************@microsof t.com...
>> >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.
>>
>>
>>


Dec 6 '05 #8
this is frustrating!

i tried creating a (more simple) client that attempts to send multiple
requests to the remote server. each request is sent and a response is
awaited in its own thread, with the theory being that since each thread has
its own connection to the remote server, everything would work out.

the transactions are all making it to the server, but my client, again, is
losing some of the responses. this is my client thread method. it seems
straight forward: open a TcpClient, send something, wait for something with
the same client, etc. I was using the ManualReset for handling timeouts, but
i'm not even worried about that right now (all of my calls to the remote
server are returning something)...also, the messages returned from the remote
server are terminated with 0x0d, so that is what i am using to know that a
response is finished. since the thread handles one send and receive, i let it
terminate once the receive loop ends.
private void ClientThread(object data)
{
TcpClient client = null;
NetworkStream netStream = null;

try
{
//TransFlag.Reset();

Console.WriteLine("In client thread");
TCPBaseSettings cs = TCPSettings();
client = new TcpClient(cs.Host, cs.Port);
netStream = client.GetStream();
netStream.Write((byte[])data, 0, ((byte[])data).Length);

int totalBytesRcvd = 0;
int bytesRcvd = 0;
const int BufferSize = 256;
// Receive buffer.
byte[] buffer = new byte[BufferSize];
while (true)
{
bytesRcvd = netStream.Read(buffer,0,BufferSize);
if (bytesRcvd > 0)
{
Console.WriteLine("Received Bytes: " +
bytesRcvd.ToString());
if (ContainsCR(buffer))
{
Console.WriteLine("Buffer contains CR");
Console.WriteLine("Thread: " +
Thread.CurrentThread.Name);
RxBytes = new byte[bytesRcvd];
Array.Copy(buffer, 0, RxBytes, 0, bytesRcvd);
//TransFlag.Set();
hasresponse = true;
break;
}
else
{
//Console.WriteLine("Buffer does not contain CR");
}
}
}

}
catch (Exception ex)
{
Console.WriteLine("ClientThread Exception: " + ex.Message);
//throw ex;
}
finally
{
netStream.Close();
client.Close();
}
Console.WriteLine("ClientThread Exiting: " +
Thread.CurrentThread.Name);
}
"Ignacio Machin ( .NET/ C# MVP )" wrote:
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" <co************@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
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" <co************@discussions.microsoft.com> wrote in
message
news:B2**********************************@microsof t.com...
> 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(respon se));
> 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" <co************@discussions.microsoft.com> wrote in
>> message
>> news:75**********************************@microsof t.com...
>> >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.
>>
>>
>>


Dec 6 '05 #9
Hi,

Are ou sure that the server does support multithreading? and it does it
correctly?

Maybe it's the server where the problems lies.
Also make sure you know the server's protocol
cheers,

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

"coloradowebdev" <co************@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
this is frustrating!

i tried creating a (more simple) client that attempts to send multiple
requests to the remote server. each request is sent and a response is
awaited in its own thread, with the theory being that since each thread
has
its own connection to the remote server, everything would work out.

the transactions are all making it to the server, but my client, again, is
losing some of the responses. this is my client thread method. it seems
straight forward: open a TcpClient, send something, wait for something
with
the same client, etc. I was using the ManualReset for handling timeouts,
but
i'm not even worried about that right now (all of my calls to the remote
server are returning something)...also, the messages returned from the
remote
server are terminated with 0x0d, so that is what i am using to know that a
response is finished. since the thread handles one send and receive, i let
it
terminate once the receive loop ends.
private void ClientThread(object data)
{
TcpClient client = null;
NetworkStream netStream = null;

try
{
//TransFlag.Reset();

Console.WriteLine("In client thread");
TCPBaseSettings cs = TCPSettings();
client = new TcpClient(cs.Host, cs.Port);
netStream = client.GetStream();
netStream.Write((byte[])data, 0, ((byte[])data).Length);

int totalBytesRcvd = 0;
int bytesRcvd = 0;
const int BufferSize = 256;
// Receive buffer.
byte[] buffer = new byte[BufferSize];
while (true)
{
bytesRcvd = netStream.Read(buffer,0,BufferSize);
if (bytesRcvd > 0)
{
Console.WriteLine("Received Bytes: " +
bytesRcvd.ToString());
if (ContainsCR(buffer))
{
Console.WriteLine("Buffer contains CR");
Console.WriteLine("Thread: " +
Thread.CurrentThread.Name);
RxBytes = new byte[bytesRcvd];
Array.Copy(buffer, 0, RxBytes, 0, bytesRcvd);
//TransFlag.Set();
hasresponse = true;
break;
}
else
{
//Console.WriteLine("Buffer does not contain
CR");
}
}
}

}
catch (Exception ex)
{
Console.WriteLine("ClientThread Exception: " + ex.Message);
//throw ex;
}
finally
{
netStream.Close();
client.Close();
}
Console.WriteLine("ClientThread Exiting: " +
Thread.CurrentThread.Name);
}
"Ignacio Machin ( .NET/ C# MVP )" wrote:
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" <co************@discussions.microsoft.com> wrote in
message
news:C3**********************************@microsof t.com...
>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" <co************@discussions.microsoft.com> wrote in
>> message
>> news:B2**********************************@microsof t.com...
>> > 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(respon se));
>> > 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" <co************@discussions.microsoft.com> wrote
>> >> in
>> >> message
>> >> news:75**********************************@microsof t.com...
>> >> >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.
>> >>
>> >>
>> >>
>>
>>
>>


Dec 6 '05 #10
i am pretty sure it does. there is a logging application on the server that
monitors the transactions, and i can see them all coming in and responding,
to the point where if i send 4 transactions and 2 of them take 15 seconds and
2 of them take 2 seconds, i see all 4 requests coming in, then the 2 "2
second" ones responding and then the 2 "15 second" ones responding. the
server uses sequence numbers so that's how i am matching them up. i've also
had a network sniffer set up and can actually see the responses coming back.

the server uses TCP, if that is what you mean. its set up to listen to a
specific port, and if i run a netstat -a (on the client and remote server) i
can see the actual connections with the established ports.

if at the base level my TcpClient should send and receive only on its own
connection, maybe its my threading that isn't working properly. in my head,
i should be able to set up 100 threads, each with its own TcpClient, and each
should send then receive without any overlapping, right?

i appreciate you input on this.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Are ou sure that the server does support multithreading? and it does it
correctly?

Maybe it's the server where the problems lies.
Also make sure you know the server's protocol
cheers,

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

"coloradowebdev" <co************@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
this is frustrating!

i tried creating a (more simple) client that attempts to send multiple
requests to the remote server. each request is sent and a response is
awaited in its own thread, with the theory being that since each thread
has
its own connection to the remote server, everything would work out.

the transactions are all making it to the server, but my client, again, is
losing some of the responses. this is my client thread method. it seems
straight forward: open a TcpClient, send something, wait for something
with
the same client, etc. I was using the ManualReset for handling timeouts,
but
i'm not even worried about that right now (all of my calls to the remote
server are returning something)...also, the messages returned from the
remote
server are terminated with 0x0d, so that is what i am using to know that a
response is finished. since the thread handles one send and receive, i let
it
terminate once the receive loop ends.
private void ClientThread(object data)
{
TcpClient client = null;
NetworkStream netStream = null;

try
{
//TransFlag.Reset();

Console.WriteLine("In client thread");
TCPBaseSettings cs = TCPSettings();
client = new TcpClient(cs.Host, cs.Port);
netStream = client.GetStream();
netStream.Write((byte[])data, 0, ((byte[])data).Length);

int totalBytesRcvd = 0;
int bytesRcvd = 0;
const int BufferSize = 256;
// Receive buffer.
byte[] buffer = new byte[BufferSize];
while (true)
{
bytesRcvd = netStream.Read(buffer,0,BufferSize);
if (bytesRcvd > 0)
{
Console.WriteLine("Received Bytes: " +
bytesRcvd.ToString());
if (ContainsCR(buffer))
{
Console.WriteLine("Buffer contains CR");
Console.WriteLine("Thread: " +
Thread.CurrentThread.Name);
RxBytes = new byte[bytesRcvd];
Array.Copy(buffer, 0, RxBytes, 0, bytesRcvd);
//TransFlag.Set();
hasresponse = true;
break;
}
else
{
//Console.WriteLine("Buffer does not contain
CR");
}
}
}

}
catch (Exception ex)
{
Console.WriteLine("ClientThread Exception: " + ex.Message);
//throw ex;
}
finally
{
netStream.Close();
client.Close();
}
Console.WriteLine("ClientThread Exiting: " +
Thread.CurrentThread.Name);
}
"Ignacio Machin ( .NET/ C# MVP )" wrote:
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" <co************@discussions.microsoft.com> wrote in
message
news:C3**********************************@microsof t.com...
>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" <co************@discussions.microsoft.com> wrote in
>> message
>> news:B2**********************************@microsof t.com...
>> > 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(respon se));
>> > 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" <co************@discussions.microsoft.com> wrote
>> >> in
>> >> message
>> >> news:75**********************************@microsof t.com...
>> >> >i am working on basically a proxy server that handles requests via
>> >> >remoting

Dec 6 '05 #11
at this point i'm guessing its just my logic for threading. i did a quick
console application that opened 10 threads that read a web page from a
server, and it behaved as i expected: the GET messages went out, and the
output was displayed as it was received, with all the threads intermingled.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace MultiThreadedClient
{
class Program
{
static void Main(string[] args)
{
Thread myThread;
RequestBroker r = new
RequestBroker(IPAddress.Parse("10.153.11.85"));

for (int i = 0; i < 10; i++)
{
myThread = new Thread(new ThreadStart(r.Connect));
myThread.Start();
}
}
private class RequestBroker
{
private IPAddress remoteHost;
public AutoResetEvent ConnectedToAllHosts = new
AutoResetEvent(false);
private int connections;

public RequestBroker(IPAddress remoteHost)
{
this.remoteHost = remoteHost;
connections = 0;
}

public void Connect()
{
TcpClient c = new TcpClient();
int connection = Interlocked.Increment(ref this.connections)
- 1;
try
{
Console.WriteLine("Connecting #" + connection.ToString());
c.Connect(remoteHost, 80);
NetworkStream netStream = c.GetStream();
string request = "GET / HTTP/1.0" + Environment.NewLine
+ Environment.NewLine;
Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
Console.WriteLine(request);
netStream.Write(bytesSent, 0, bytesSent.Length);

int bytes;
byte[] bytesReceived = new byte[256];
bool done = false;
do
{
bytes = netStream.Read(bytesReceived, 0,
bytesReceived.Length);
if (bytes > 0)
{
Console.WriteLine("Read #" +
connection.ToString() + " for " + bytes.ToString() + " bytes.");
Console.Write("Reading #" +
connection.ToString() + Encoding.ASCII.GetString(bytesReceived, 0, bytes));
Console.WriteLine("Done Reading #" +
connection.ToString());
}

}
while (!done);

}
catch (Exception exception)
{
Console.WriteLine("Exception: " + exception.Message);
}
Console.WriteLine("Closing #" + connection.ToString());
c.Close();
}
}
}
}
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Are ou sure that the server does support multithreading? and it does it
correctly?

Maybe it's the server where the problems lies.
Also make sure you know the server's protocol
cheers,

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

"coloradowebdev" <co************@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
this is frustrating!

i tried creating a (more simple) client that attempts to send multiple
requests to the remote server. each request is sent and a response is
awaited in its own thread, with the theory being that since each thread
has
its own connection to the remote server, everything would work out.

the transactions are all making it to the server, but my client, again, is
losing some of the responses. this is my client thread method. it seems
straight forward: open a TcpClient, send something, wait for something
with
the same client, etc. I was using the ManualReset for handling timeouts,
but
i'm not even worried about that right now (all of my calls to the remote
server are returning something)...also, the messages returned from the
remote
server are terminated with 0x0d, so that is what i am using to know that a
response is finished. since the thread handles one send and receive, i let
it
terminate once the receive loop ends.
private void ClientThread(object data)
{
TcpClient client = null;
NetworkStream netStream = null;

try
{
//TransFlag.Reset();

Console.WriteLine("In client thread");
TCPBaseSettings cs = TCPSettings();
client = new TcpClient(cs.Host, cs.Port);
netStream = client.GetStream();
netStream.Write((byte[])data, 0, ((byte[])data).Length);

int totalBytesRcvd = 0;
int bytesRcvd = 0;
const int BufferSize = 256;
// Receive buffer.
byte[] buffer = new byte[BufferSize];
while (true)
{
bytesRcvd = netStream.Read(buffer,0,BufferSize);
if (bytesRcvd > 0)
{
Console.WriteLine("Received Bytes: " +
bytesRcvd.ToString());
if (ContainsCR(buffer))
{
Console.WriteLine("Buffer contains CR");
Console.WriteLine("Thread: " +
Thread.CurrentThread.Name);
RxBytes = new byte[bytesRcvd];
Array.Copy(buffer, 0, RxBytes, 0, bytesRcvd);
//TransFlag.Set();
hasresponse = true;
break;
}
else
{
//Console.WriteLine("Buffer does not contain
CR");
}
}
}

}
catch (Exception ex)
{
Console.WriteLine("ClientThread Exception: " + ex.Message);
//throw ex;
}
finally
{
netStream.Close();
client.Close();
}
Console.WriteLine("ClientThread Exiting: " +
Thread.CurrentThread.Name);
}
"Ignacio Machin ( .NET/ C# MVP )" wrote:
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" <co************@discussions.microsoft.com> wrote in
message
news:C3**********************************@microsof t.com...
>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" <co************@discussions.microsoft.com> wrote in
>> message
>> news:B2**********************************@microsof t.com...
>> > 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(respon se));
>> > 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" <co************@discussions.microsoft.com> wrote
>> >> in
>> >> message
>> >> news:75**********************************@microsof t.com...
>> >> >i am working on basically a proxy server that handles requests via
>> >> >remoting

Dec 6 '05 #12
Hi,
"coloradowebdev" <co************@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
. i've also
had a network sniffer set up and can actually see the responses coming
back.
Were they correct?
the server uses TCP, if that is what you mean. its set up to listen to a
specific port, and if i run a netstat -a (on the client and remote server)
i
can see the actual connections with the established ports.
No, I mean to what application protocol it uses, the format of the message
it send/receive
if at the base level my TcpClient should send and receive only on its own
connection, maybe its my threading that isn't working properly. in my
head,
i should be able to set up 100 threads, each with its own TcpClient, and
each
should send then receive without any overlapping, right?
Correctly.

The one part I do not like of your code is :

netStream.Read(buffer,0, 256);

Try this, read a single byte at a time and just store it in your buffer,
also what happens if the answer is longer than 256? in your code there is
nothing to prevent/treat this.

Change it like this:
ArrayList bytes = new ArrayList();
byte[] buffer = new byte[1];
while( true )
{
netstream.Read( buffer, 0, 1 )
bytes.Add( buffer[0] )
if ( IsCR ( buffer[0] )
break; // .... do your stuff
}
//return the value
return bytes.ToArray( typeof( byte) );

If CR constains more than one char you have to change a little bit it. but
the above should work,
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
i appreciate you input on this.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Are ou sure that the server does support multithreading? and it does it
correctly?

Maybe it's the server where the problems lies.
Also make sure you know the server's protocol
cheers,

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

"coloradowebdev" <co************@discussions.microsoft.com> wrote in
message
news:C5**********************************@microsof t.com...
> this is frustrating!
>
> i tried creating a (more simple) client that attempts to send multiple
> requests to the remote server. each request is sent and a response is
> awaited in its own thread, with the theory being that since each thread
> has
> its own connection to the remote server, everything would work out.
>
> the transactions are all making it to the server, but my client, again,
> is
> losing some of the responses. this is my client thread method. it
> seems
> straight forward: open a TcpClient, send something, wait for something
> with
> the same client, etc. I was using the ManualReset for handling
> timeouts,
> but
> i'm not even worried about that right now (all of my calls to the
> remote
> server are returning something)...also, the messages returned from the
> remote
> server are terminated with 0x0d, so that is what i am using to know
> that a
> response is finished. since the thread handles one send and receive, i
> let
> it
> terminate once the receive loop ends.
>
>
> private void ClientThread(object data)
> {
> TcpClient client = null;
> NetworkStream netStream = null;
>
> try
> {
> //TransFlag.Reset();
>
> Console.WriteLine("In client thread");
> TCPBaseSettings cs = TCPSettings();
> client = new TcpClient(cs.Host, cs.Port);
> netStream = client.GetStream();
> netStream.Write((byte[])data, 0, ((byte[])data).Length);
>
> int totalBytesRcvd = 0;
> int bytesRcvd = 0;
> const int BufferSize = 256;
> // Receive buffer.
> byte[] buffer = new byte[BufferSize];
> while (true)
> {
> bytesRcvd = netStream.Read(buffer,0,BufferSize);
> if (bytesRcvd > 0)
> {
> Console.WriteLine("Received Bytes: " +
> bytesRcvd.ToString());
> if (ContainsCR(buffer))
> {
> Console.WriteLine("Buffer contains CR");
> Console.WriteLine("Thread: " +
> Thread.CurrentThread.Name);
> RxBytes = new byte[bytesRcvd];
> Array.Copy(buffer, 0, RxBytes, 0,
> bytesRcvd);
> //TransFlag.Set();
> hasresponse = true;
> break;
> }
> else
> {
> //Console.WriteLine("Buffer does not contain
> CR");
> }
> }
> }
>
> }
> catch (Exception ex)
> {
> Console.WriteLine("ClientThread Exception: " +
> ex.Message);
> //throw ex;
> }
> finally
> {
> netStream.Close();
> client.Close();
> }
> Console.WriteLine("ClientThread Exiting: " +
> Thread.CurrentThread.Name);
> }
>
>
> "Ignacio Machin ( .NET/ C# MVP )" wrote:
>
>> 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" <co************@discussions.microsoft.com> wrote in
>> message
>> news:C3**********************************@microsof t.com...
>> >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" <co************@discussions.microsoft.com> wrote
>> >> in
>> >> message
>> >> news:B2**********************************@microsof t.com...
>> >> > 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(respon se));
>> >> > 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" <co************@discussions.microsoft.com>
>> >> >> wrote
>> >> >> in
>> >> >> message
>> >> >> news:75**********************************@microsof t.com...
>> >> >> >i am working on basically a proxy server that handles requests
>> >> >> >via
>> >> >> >remoting

Dec 7 '05 #13
Is the server available publicly? Can I program against it just to check?

Ab.

"coloradowebdev" <co************@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
their server does accept multiple connections. i can watch my transactions being processed on their server, its just that my client (when it tries to
send multiple transactions and wait for a response) doesn't handle the
responses properly (their server tries to send the responses, my client just stops listening, or whatever).

"Abubakar" wrote:
i've actually tried a number of different approaches, which i will try to

synchronous or asynchronous doesnt matter, if the server is just programmed to accept one connection than it'll just accpt one connection. It could take multiple connections but maybe its not programmed that way. Have you
contacted the person who built the server? I think the way it used to work serially, as you said, its working that same way using tcp and may not take concurrent users/connections.
Just for your information, If I have to program a server to accept multiple clients I do something like this:

while ( true )
{
TcpClient client = listening_socket.AcceptTcpClient(); //blocking call // ... do processing with client, maybe open it in a new thread for
communicating, and come back to listening mode.

}

But it seems that they accept a connection, than communicates with the
client and when the client disconnects 'than' go into listening state
again, so to do one transaction at a time.

Ab.
http://joehacker.blogspot.com

"coloradowebdev" <co************@discussions.microsoft.com> wrote in message news:B2**********************************@microsof t.com...
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(respon se));
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" <co************@discussions.microsoft.com> wrote in

message
> news:75**********************************@microsof t.com...
> >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.
>
>
>


Dec 8 '05 #14

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

Similar topics

0
by: Hameed Khan | last post by:
hi all, i am getting some problems with my first socket script. can any one of you point me why this is happening. the server script suppose to accept one connection at a time and send countdown...
4
by: mfaujour | last post by:
I HAVE THIS PYTHON PROGRAMM: $ cat socpb.py import BaseHTTPServer, SocketServer, os, socket, threading # the server initialisation server = SocketServer.TCPServer((socket.gethostname(),...
1
by: Rolln_Thndr | last post by:
I'm vey new to network programing and have a few rather fundemental questions. I'm creating a very basic UDP proxy server and having a few issues regarding the sockets. Is it possible to change...
2
by: zhebincong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
0
by: Markus S. | last post by:
Hello! I have two questions about Socket.Select(): 1) How is it possible to interrupt Socket.Select()? I'm calling Socket.Select() in a worker thread. When new sockets are added (from another...
4
by: seets375 | last post by:
Hi, I have two ethernet interfaces on my system, with IPs assigned to the interfaces from different subnets (e.g. eth1 - 10.10.10.10 and eth2 - 20.20.20.20 ). I'm connecting these interfaces to...
8
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi all, I am new to .net technologies. ASP.NET supports socket programming like send/receive in c or c++? I am developing web-site application in asp.net and code behind is Visual C#. In...
6
by: ahlongxp | last post by:
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.