我是Pub/Sub的新手,十年没有完成TCP ......请帮忙!我有一个完美的Windows窗体Pub Sub应用程序。经过大量测试后,我将“Pub”应用程序转换为控制台应用程序(它最终将成为服务应用程序)...问题是_proxy.Publish(alertData,topicName1); “SendEvent()”方法内由于超时而失败。PubSub在转换为控制台应用程序后失败发布
以下例外情况如下:
套接字连接被中止。这可能是由处理您的消息时出错或远程主机超出接收超时或基础网络资源问题引起的。本地套接字超时为'00:00:59.9529953'。
(值得注意的一个点,整个应用低于59秒运行一次到达“发布”命令之前)
我比较WinApp和控制台应用程序并排而没有看到问题...我搜索了谷歌和超过6个小时,并尝试了我能想到的一切。请帮忙!!!请指出我是否做了一些不太聪明的事情,比如错过了一些小的(或主要的)哑巴,细节!谢谢
有效代码如下:
class Program
{
static void Main(string[] args)
{
PublisherClass pb = new PublisherClass();
pb.PublisherClassStart();
}
}
public class PublisherClass
{
public List<String> ListOfTopics = new List<String>();
public List<String> ButtonCreatedList = new List<String>();
public List<RData> DataList = new List<RData>();
private TcpListener tcpListener;
private Thread listenThread;
IPublishing _proxy;
private System.Timers.Timer tmrEvent;
/* static */
TcpClient QFeedClientChannel = null;
//call the entitiesmodel customer list and create all topics from the.... here...
public void PublisherClassStart()
{
CreateProxy();
_eventCounter = 0;
QueueViaTCPListener();
CreateTopics();
Console.WriteLine("Press any key to Send Data to Server");
while (true)
{
var Val = Console.ReadLine();
object sender = null;
EventArgs e = null;
SendEvent(sender, e);
}
Thread.Sleep(10000); // wait for connections and topics to stabilize and then start firing the timer.
tmrEvent = new System.Timers.Timer(100);
tmrEvent.Elapsed += SendEvent;
tmrEvent.Start();
}
static public void CreateTopics()
{
... }
private void CreateProxy()
{
string endpointAddressInString = ConfigurationManager.AppSettings["EndpointAddress"];
EndpointAddress endpointAddress = new EndpointAddress(endpointAddressInString);
NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None);
_proxy = ChannelFactory<IPublishing>.CreateChannel(netTcpBinding, endpointAddress);
}
void SendEvent(object sender, EventArgs e)
{
try
{
lock (ListOfTopics)
{
lock(DataList)
{
foreach (...)
{
...
alertData = PrepareEvent(topicName1, topicData);
_proxy.Publish(alertData, topicName1);
_eventCounter += 1;
//txtEventCount.Text = _eventCounter.ToString();
i++;
}
}
}
}
}
catch (Exception ex)
{
int i = 0;
}
//tmrEvent.Start();
}
仅供参考:失败的代码行接近底部......异常中的整数仅仅是调试代码,以便将断点放在...... – 2014-09-22 23:07:33