我正在嘗試使用C#綁定爲zeromq構建helloworld示例。我已成功構建.Net庫(clrzmq.dll)。我正嘗試使用單聲道附帶的csharp編譯器構建單個csharp源代碼,構建命令行。使用命令行單聲道構建zeromq helloworld示例
我已經包含下面的源文件的內容:
using System;
using System.Collections.Generic;
using System.Threading;
using System.Text;
/**
* Author: Randy Dryburgh
* Email: [email protected]
* License: This example code licensed under the MIT/X11 license.
*/
namespace Examples {
class hwserver {
static void Main(string[] args) {
// allocate a buffer
byte[] zmq_buffer = new byte[1024];
// Prepare our context and socket
ZMQ.Context context = new ZMQ.Context(1);
ZMQ.Socket socket = context.Socket(ZMQ.REP);
socket.Bind("tcp://*:5555");
while (true) {
try {
// Wait for next request from client
socket.Recv(out zmq_buffer);
string request = Encoding.ASCII.GetString(zmq_buffer);
// log that we got one
Console.WriteLine("Received request: [%s]", request);
// Do some 'work'
Thread.Sleep(1);
// Send reply back to client
socket.Send(Encoding.ASCII.GetBytes("World".ToCharArray()));
} catch (ZMQ.Exception z) {
// report the exception
Console.WriteLine("ZMQ Exception occurred : {0}", z.Message);
}
}
}
}
}
下面是一個命令行命令我使用和錯誤消息我得到。
[email protected]:~/work/dev/c++/3rdparty/zeromq/zguide/examples/C#$ mcs hwserver.cs.v1 -lib:/home/oompah/work/dev/c++/3rdparty/zeromq/clrzmq2/clrzmq/bin/Release/ -r:clrzmq.dll
hwserver.cs.v1(20,53): error CS0234: The type or namespace name `REP' does not exist in the namespace `ZMQ'. Are you missing an assembly reference?
hwserver.cs.v1(20,42): error CS1502: The best overloaded method match for `ZMQ.Context.Socket(ZMQ.SocketType)' has some invalid arguments
/home/oompah/work/dev/c++/3rdparty/zeromq/clrzmq2/clrzmq/bin/Release/clrzmq.dll (Location of the symbol related to previous error)
hwserver.cs.v1(20,42): error CS1503: Argument `#1' cannot convert `object' expression to type `ZMQ.SocketType'
hwserver.cs.v1(26,28): error CS1502: The best overloaded method match for `ZMQ.Socket.Recv(params ZMQ.SendRecvOpt[])' has some invalid arguments
/home/oompah/work/dev/c++/3rdparty/zeromq/clrzmq2/clrzmq/bin/Release/clrzmq.dll (Location of the symbol related to previous error)
hwserver.cs.v1(26,28): error CS1615: Argument `#1' does not require `out' modifier. Consider removing `out' modifier
Compilation failed: 5 error(s), 0 warnings
我不知道爲什麼會有編譯什麼是表面上的「小事」 Hello World示例與指南提供的代碼,當如此多的錯誤。
zeromq的.Net程序集成功構建,所以我不明白爲什麼我得到上述錯誤(假設上面的代碼沒有錯誤) - 我該如何解決這個問題?
我在Ubuntu 10.0.4 LTS,64位上運行。
[編輯]是我的單身材
詳情如下:
Mono JIT compiler version 2.10.2 (tarball Wed Jul 20 17:42:26 BST 2011)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
我跑單2.10。請看我編輯的問題的全部細節。 – oompahloompah
請參閱新版本的帖子。 – Argbart2
非常感謝 - 它能夠正確編譯。我也欺騙了客戶端並對其進行了修改(現在也是正確構建的)。你是如何知道所需的改變的 - 你是否熟悉zeromq ...或者你自己解決了它(如果是這樣,怎麼做?) – oompahloompah