Tag: c ++

Java和C#应用程序之间的套接字通信

我有02个应用程序,一个用java编写,另一个用C#编写。 我需要在它们之间交换数据(字符串),因此我使用套接字连接。 目前,C#应用程序充当服务器,Java应用程序充当客户端。 C#应用程序将持续侦听端口“7777”,Java应用程序将启动一个套接字“localhost:7777”并使用该套接字将数据发送到C#服务器。 我不关闭它们之间的连接,因为我需要经常交换数据。 在我的C#服务器应用程序有时需要将一些字符串发送到Java客户端应用程序之前,一切都很好。 我想使用另一个端口使我的java应用程序成为服务器,C#应用程序也将成为客户端。 但我觉得这不是一个好的解决方案。 P / S:是的,socket是双向的,在我当前的应用程序中,我可以将来自我的C#应用​​程序的字符串数据发送回Java应用程序,但只有当Java应用程序首先将字符串发送到C#应用程序并且现在它正在等待时来自C#应用程序的响应数据。 因此,我想问一下是否还有其他更好的解决方案? 如果我们总共只使用1个端口吗? 非常感谢你。

如何触发我的代码中的按钮单击?

如何直接在我的代码中触发按钮单击? 我有这样的代码: namespace App1 { /// /// An empty page that can be used on its own or navigated to within a Frame. /// public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } protected override void OnNavigatedTo(NavigationEventArgs e) { // fire a click ebent von the “Button” MyBtn } private void […]

使用protobuf-net发布反序列化(protocolBuffer)序列化数据

我使用protobuf-net对数据进行了序列化,并且能够在C#中进行相同的处理。 放一个C#dummy w# var file = File.Create(“animal.bin”); //Creating Msg – Fill the Data animal.id = “1”; animal.Name = “Rat”; animal.host = “Cheetha”; ProtoBuf.Serializer.SerializeWithLengthPrefix(file, animal, PrefixStyle.Base128, 1); animal.id = “2”; animal.Name = “Cat”; animal.host = “Cheetha”; ProtoBuf.Serializer.SerializeWithLengthPrefix(file, animal, PrefixStyle.Base128, 1); …. animal.id = “4”; animal.name = “Cheetha”; animal.host = “Cheetha”; ProtoBuf.Serializer.SerializeWithLengthPrefix(file, animal, PrefixStyle.Base128, 1); //Done Creating […]

如何在将C#字符串传递给javascript时优雅地转义单引号和双引号

我有一个C#字符串需要传递给页面然后发送回服务器。 它需要能够处理单引号,双引号和可能导致问题的任何其他标准字符。 我正在使用MVC4和razor。 现在我将字符串传递给javascript。 我有这样的事情: var str = ‘@Html.Raw(Model.SomeString.Replace(“‘”, @”\'”))’; 这很好用,但我想知道是否有更好,更优雅的方式来转义将传递给javascript的C#字符串。 我已经尝试将值存储在隐藏字段中,如下所示: @Html.Hidden(x => x.SomeString) 但是当我去抓取价值时,它会出现双引号问题。 编辑:结果是Html.Hidden问题是由其他东西引起的 任何帮助是极大的赞赏! 注意:必须在IE9和10中工作。没有ViewBags。

从GridView ItemTemplate按钮执行Javascript函数单击ASP.NET Web窗体

我有一个DataGridView,它有两个动态生成的ItemTemplate按钮列。 我点击它们时触发的两个按钮都有代码隐藏,但是当点击btnInfo按钮时我还需要一个javascript函数来运行 标记: <asp:Button ID="btnInfo" runat="server" CausesValidation="false" CommandName="MoreInfo" Text="More Info" CommandArgument='’/> <asp:Button ID="btnAdd" runat="server" CausesValidation="false" CommandName="AddItem" Text="Add To Log" CommandArgument='’ /> ‘ 我有一个名为populateLabel()的javascript函数,我需要在单击btnInfo时触发。 有任何想法吗? (我知道有类似的问题已被问过,我在整个post中查看并尝试了一些事情,但似乎没有任何工作) 编辑:这是ItemTemplate按钮的代码隐藏的样子 protected void gridResutls_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { // Kick out if neither of the two dynamically created buttons have been clicked if (e.CommandName != “MoreInfo” && e.CommandName != “AddItem”) […]

C#代码无法“看到”我的C ++ DLL中的方法

我有一个用C ++编写的代码(我没有编写)并希望在C#中使用它,所以我决定创建一个dll并从那里使用这个类。 我对C ++知之甚少,并且在我的C#项目中引用这个类的方法时遇到了问题。 C ++代码是这样的: #ifndef BeamAn_class #define BeamAn_class #define DllExport __declspec( dllexport ) #include #include using namespace std; public class DllExport BeamAn { public: BeamAn(); ~BeamAn(); bool SetGeometry(vector); //I didn’t put the DllExport here because I already did it for the whole class. It’s okay to do this, right? //other public methods an […]

为什么不为ActiveMQ Temp Queue创建消费者?

除SimpleMessageListenerContainer选项外,不会为临时队列创建使用者。 我不会将SimpleMessageListenerContainer用于此处遇到的一些问题。 以下代码不起作用…(即使没有创建临时队列) using (IConnection connection = connectionFactory.CreateConnection()) using (ISession session = connection.CreateSession()) { IDestination destination = SessionUtil.GetDestination(session, aQueueName); var replyDestination = session.CreateTemporaryQueue(); // Create a consumer and producer using (IMessageProducer producer = session.CreateProducer(destination)) { // Start the connection so that messages will be processed. connection.Start(); IBytesMessage request = session.CreateBytesMessage(aMsg); request.NMSReplyTo = replyDestination; IMessageConsumer consumer […]

如何获取可用video捕获设备列表

我正在使用DirectShow.Net创建一个项目,该项目使用Visual C#显示Windows窗体中的网络摄像头视图的预览。 我想首先获得一系列可用的video设备,以便我可以在内置网络摄像头或USB网络摄像头之间进行选择。 我已经看到了几个用C ++完成的例子,例如msdn“ http://msdn.microsoft.com/en-us/library/windows/desktop/dd377566(v=vs.85).aspx ”。 但是,由于我不知道任何C ++,我不知道如何将此代码转换为C#。

如何以编程方式登录雅虎网站

马上就好 – 请不要建议我使用Yahoo API。 我这样做纯粹是一种学习经验,使用API​​会破坏目的。 当我登录Yahoo邮件(mail.yahoo.com)或Flickr时,我正在使用Fiddler来查看HTTP流量。 我看到浏览器将数据发布到https://login.yahoo.com/config/login 。 样本post数据是: .tries = 1的.src = flickrsignin&.md5 =&哈希=&JS =。最后=促销= INTL。= US&.lang = EN-US&.bypass =&合作伙伴=&U = 811cdp17imj21&.V = 0&.challenge = iwQ4dJLk0KhUP8Xlpyji_8ftQ.fe&.yplus =&emailCode =&PKG =&stepid =&EV =&hasMsgr = 1&.chkP = Y&.done = HTTPS%3A%2F%2Flogin.yahoo.com%2Fconfig%2Fvalidate%3F的.src%3Dflickrsignin%26.pc%3D8190%26.scrumb%3D0%26.pd%的3Dc%253DJvVF95K62e6PzdPu7MBv2V8-%26.intl%3DUS%26.done%3Dhttp%253A%252F%252Fwww.flickr.com%252Fsignin% 252Fyahoo%252F%253Fredir%253D%25252Fphotos%25252Ffriends%25252F&.PD = flickrsignin_ver%3D0%26C%3DJvVF95K62e6PzdPu7MBv2V8-%26ivt%3D%26sg%3D&.WS = 1&.cp = 0&垫= 15&AAD = 15&弹出= 1&登录名= nkisnksd&的passwd = noasno& .save =&passwd_raw = […]

使用纯虚方法包装类

我有一个非托管的DLL,它包含一个只有纯虚方法的类(回调类型): class PAClient { public: __declspec(dllexport) virtual void SetCalculationStarted() = 0; __declspec(dllexport) virtual void SetCalculationStopped() = 0; } 现在我必须将这些函数调用发送到托管C#代码并决定使用接口。 这就是我所做的: public interface class IPAClientWrapper { void SetCalculationStarted(); void SetCalculationStopped(); }; private class PAClientWrapper : public PAClient { private: gcroot callBack; public: PAClientWrapper(IPAClientWrapper^ c) { callBack = c; } void SetCalculationStarted() { callBack->SetCalculationStarted(); } void SetCalculationStopped() […]