插座问题 [英] socket questions

查看:56
本文介绍了插座问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一种代理服务器,它通过远程处理来自客户端的
来处理请求,并通过TCP对第三方服务器执行交易。


远程站点就像一个冠军。我的问题是对远程服务器执行

交易并将响应返回给

远程客户端。我可以打开套接字,如果我一次执行一个

交易,一切都很好。当我的代理服务器

尝试执行多个交易时,我在套接字上遗漏了一些内容

end。我已尝试过同步和异步,但看起来好像

套接字在收到一个响应后停止监听并忽略

其他待处理事务。


我已经尝试了许多不同的方法,并在

forums.microsoft板上发布了消息。我不得不相信某个人,某个地方已经建立了像这样的交易型系统。但是我收到的大部分样本和建议都是指向服务器监听并接受多个客户端的b
而不是一个连接到远程服务器的应用程序

有多个并发(客户端)连接。


如果有人有任何有用的链接或建议,我们将不胜感激。

提前谢谢。

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.

推荐答案



发布用于与远程TCP服务器通信的代码,你是否使用多线程?
?每个线程产生一个连接?


欢呼,

-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州交通局

" coloradowebdev" <共************ @ discussions.microsoft.com>在消息中写道

news:75 ********************************** @ microsof t.com ...
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...
我的工作基本上是一个代理服务器,它通过远程处理来自客户端的请求,并通过TCP对第三方服务器执行事务。远程站点就像一个冠军。我的问题是针对远程服务器执行
事务并将响应返回给远程客户端。我可以打开套接字,如果我一次执行一个
事务,一切都很好。当我的代理服务器尝试执行多个事务时,我在
socket
结束时遗漏了一些东西。我已经尝试过同步和异步,但它似乎只是在接收到一个响应后套接字停止侦听并忽略
其他待处理的事务。

我已经尝试了许多不同的方法,并在
forums.microsoft板上发布了消息。我不得不相信某个人,某个地方已经建立了像这样的交易型系统。但我收到的大多数样本和
建议都指向服务器监听和接受多个客户端,而不是一个连接到远程服务器的应用程序<有许多并发(客户端)连接。

如果有人有任何有用的链接或建议,我们将不胜感激。
提前感谢。
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.


我实际上尝试了很多不同的方法,我将尝试在下面总结一下......


同步:这适用于一个交易,但发送超过

一个没有(在等待前一个交易的响应时发送

导致读取失败(不返回))


[发送同步,然后]

int i = sock.Receive(buffer,0,sock.Available,SocketFlags .None);

byte [] response = new byte [i];

Array.Copy(buffer,0,response,0,i);

//Console.Wr iteLine(" Out of Transact:" +

Comcast.Common.Encoding.HexEncoder.ToString(respon se));

返回响应;


异步:


i剥离了异步读取的最后一个版本。基本上,它是异步发送时同步发送的。
。当某些东西收到
时,如果它包含特殊的终止字符,它会将服务器响应作为事件参数的事件引发

。代码是来自MSDN网站的异步样本和其他参考资料的组合

使用BeginReceive的网络上的



我知道这不是很难。我正在将

应用程序的TCP功能添加到以前基于所有序列的应用程序中。串口

的逻辑是检查端口是否可用,如果是发送,锁定端口

直到收到回复,返回响应,关闭港口。我不是一个很好的TCP / IP人物,但我认为那里应该有一些信息

会让我走上正确的道路。


Ignacio Machin(.NET / C#MVP)"写道:
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:


发布用于与远程TCP服务器通信的代码,是否使用多线程?每个线程产生一个连接?

欢呼,

- Ignacio Machin,
ignacio.machin at dot.state.fl.us
" coloradowebdev" <共************ @ discussions.microsoft.com>在消息中写道
新闻:75 ********************************** @ microsof t.com。 ..
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...
我正在研究一种代理服务器,它通过远程处理来自客户端的请求来处理请求,并通过TCP来执行针对第三方服务器的事务。
<远程站点像冠军一样工作。我的问题是针对远程服务器执行
事务并将响应返回给远程客户端。我可以打开套接字,如果我一次执行一个
事务,一切都很好。当我的代理服务器尝试执行多个事务时,我在
socket
结束时遗漏了一些东西。我已经尝试过同步和异步,但它似乎只是在接收到一个响应后套接字停止侦听并忽略
其他待处理的事务。

我已经尝试了许多不同的方法,并在
forums.microsoft板上发布了消息。我不得不相信某个人,某个地方已经建立了像这样的交易型系统。但我收到的大多数样本和
建议都指向服务器监听和接受多个客户端,而不是一个连接到远程服务器的应用程序<有许多并发(客户端)连接。

如果有人有任何有用的链接或建议,我们将不胜感激。
提前感谢。
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.



>我实际上已经尝试了许多不同的方法,我将尝试同步或异步无关紧要,如果服务器刚刚编程,则需要b / b
到接受一个连接,而不是只是一个连接。可能需要

多个连接,但可能没有这样编程。你有没有和b $ b联系过构建服务器的人?我认为它以前的工作方式是连续工作,如你所说,它使用tcp以同样的方式工作,可能不需要

并发用户/连接。

仅供参考,如果我必须对服务器进行编程以接受多个

客户端,我会执行以下操作:


while(true)

{

TcpClient client = listening_socket.AcceptTcpClient(); //阻止调用

// ...使用客户端进行处理,也许可以在新线程中打开它进行通信,然后回到监听模式。


}


但似乎他们接受连接,而不是与

客户端进行通信,以及当客户端断开连接时'比''再次进入聆听状态

,所以一次做一笔交易。


Ab。
http://joehacker.blogspot.com

" coloradowebdev" <共************ @ discussions.microsoft.com>在消息中写道

新闻:B2 ********************************** @ microsof t.com ...
> 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...
我实际上已经尝试了很多不同的方法,我将尝试总结如下......

同步:这适用于一个交易,但发送任何更多
而不是(在等待前一个
交易的响应时发送导致读取失败(不返回))

[发送同步,然后]
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));
返回响应;

异步:

我删除了异步读取的最后一个版本。基本上,
在异步监听时同步发送。收到某些东西时,如果它包含特殊的终止字符,那么
会将服务器响应作为事件参数引发一个事件。代码是来自MSDN站点的异步样本和使用BeginReceive的网上其他
引用的组合。

我知道这不是很难。我正在为之前基于串口的应用程序添加TCP功能。串口中的逻辑是检查端口是否可用,如果是发送,则锁定端口
直到收到某些内容,返回响应,关闭端口。我不是
a大TCP / IP的人,但我认为应该有一些信息可以让我走上正确的道路。

Ignacio Machin (.NET / C#MVP)"写道:
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:


发布用于与远程TCP服务器通信的代码,
你使用的是多线程吗?每个线程产生一个连接?

欢呼,

- Ignacio Machin,
ignacio.machin at dot.state.fl.us
" coloradowebdev" <共************ @ discussions.microsoft.com>写在
消息新闻:75 ********************************** @ microsof t.com。 ..
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...
我的工作基本上是一个代理服务器,通过
从客户端远程处理请求,并通过TCP对第三方服务器
执行事务。
<远程站点像冠军一样工作。我的问题是对远程服务器执行
事务并将响应返回给远程客户端
。我可以打开套接字,如果我一次执行
一笔交易,一切都很好。当我的代理
服务器尝试执行多个事务时,我在
socket
结束时遗漏了一些东西。我已尝试同步和异步,但它只是
似乎在收到一个响应后套接字停止侦听并忽略
其他待处理事务。

我已经尝试了许多不同的方法,并在forum.microsoft板上的
上发布了消息。我不得不相信某个人,某个地方已经建立了像这样的交易型系统。但我收到的大部分样本和
建议都指向服务器监听和接受多个客户端,而不是一个连接到远程$ b的应用程序$ b服务器有多个并发(客户端)连接。

如果有人有任何有用的链接或建议,它将是
赞赏。提前谢谢。
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.




这篇关于插座问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆