|
Try this.[^]
Bob Dole The internet is a great way to get on the net.
2.0.82.7292 SP6a
|
|
|
|
|
hi guys . i have many client that are connected to the server .
i can connect to the server completely with out any wrong in my code from my clients .
and the server response the client pretty fine .
okay , what do i need to do , is that if one client send some data to the server , i need the server to response to all the clients . like
Server/Client []
now the server just can respond the client that send the data .
any help i'll be greatfull.
i hope you got what i mean .
modified 12-Jan-13 13:57pm.
|
|
|
|
|
My advice is the same as I offer in response to most socket-related programming questions: don't roll your own, there's no point. Socket code is hard to write well and even harder to test thoroughly.
Instead, spend a bit of time getting your head around ZeroMQ[^]. Trust me, it will be time well spent. What you are trying to do is easily achieved with ZeroMQ. Look at the dealer-router & publish-subscribe patterns. I think this is the sort of thing you're after (taken from the ZeroMQ Guide) :-
https://github.com/imatix/zguide/raw/master/images/fig59.png[^]
Just to show how easy things can be with ZeroMQ, here's the complete code for a bare-bones chat client & server console app that does basically what you're after.
First, the server:-
using System;
using System.Text;
using ZeroMQ;
namespace ChatServer
{
class Server
{
static void Main(string[] args)
{
ZmqDealerSocket dealer = new ZmqDealerSocket();
dealer.Bind(args[0]);
ZmqPublishSocket publisher = new ZmqPublishSocket();
publisher.Bind(args[1]);
dealer.OnReceived += delegate(Byte[] bytes, bool multipart)
{
Console.WriteLine("Received from client: " + Encoding.UTF8.GetString(bytes));
publisher.Send(bytes);
};
while (true)
System.Threading.Thread.Sleep(1000);
}
}
}
...and the Client :-
using System;
using System.Text;
using ZeroMQ;
namespace ChatClient
{
class Client
{
static void Main(string[] args)
{
ZmqDealerSocket dealer = new ZmqDealerSocket();
dealer.Connect(args[0]);
ZmqSubscribeSocket subscriber = new ZmqSubscribeSocket();
subscriber.Connect(args[1]);
subscriber.Subscribe("");
subscriber.OnReceived += delegate(byte[] bytes, bool multipart)
{
string[] msg = Encoding.UTF8.GetString(bytes).Split('|');
Console.WriteLine(String.Format("{0}: {1}", msg[0], msg[1]));
};
while (true)
dealer.Send(args[2] + "|" + Console.ReadLine());
}
}
}
Finally, a batch file, test.bat, to demo it...
start "Server" cmd /T:8F /k ChatServer.exe tcp:
start "Jim" cmd /T:8E /k ChatClient.exe tcp:
start "Dave" cmd /T:8E /k ChatClient.exe tcp:
start "Pete" cmd /T:8E /k ChatClient.exe tcp:
How easy could it be???
Let me know if you want the VS2010 solution zip & ZeroMQ wrapper DLL I used...
modified 13-Jan-13 7:30am.
|
|
|
|
|
pt1401 wrote: Instead, spend a bit of time getting your head around ZeroMQ[^].
Interesting.
Have you used it in any high volume systems? Where that would be proven production performance or realistic performance profiling?
|
|
|
|
|
Nope, not personally, though many people have. We use it to pass messages between sites on our EPOS systems, but it's low-volume stuff.
ZeroMQ is very fast. Here[^] are the official performance tests on the ZeroMQ site, and this[^] is a performance comparison between RabbitMQ, ZeroMQ and QPid on Apache. ZeroMQ was over 60 times faster than RabbitMQ and 250 times faster than Qpid. Note, however, that these tests were a C++ application. Putting a C# wrapper around ZeroMQ slows it down somewhat, but makes it *so* easy to use
UPDATE: The RabbitMQ/ZeroMQ/Qpid test in the link above may not have been fair - see the comments regarding whether message persistence was enabled. Final opinion seems to be use ZeroMQ for socket comms but if you need an MSMQ-type message queue with message persistence use an AMQP app like RabbitMQ...
|
|
|
|
|
pt1401 wrote: are the official performance tests on the ZeroMQ site
Unfortunately I don't place much credence on benchmarks. Real world stuff is always more messy.
|
|
|
|
|
hi , ty for this info , they have really help me out . im wondering if you can send it to me by this gmail mohammad.kaab@gmail.com.
ty
|
|
|
|
|
|
hi im sorry for bothering you with my stupid question .
Server :
ZmqDealerSocket dealer = new ZmqDealerSocket();
dealer.Bind("tcp://127.0.0.1:8000");
ZmqPublishSocket publisher = new ZmqPublishSocket();
publisher.Bind("tcp://127.0.0.1:8200");
Client_1 :
ZmqDealerSocket dealer = new ZmqDealerSocket();
dealer.Connect("tcp://127.0.0.1:8000");
ZmqSubscribeSocket subscriber = new ZmqSubscribeSocket();
subscriber.Connect("tcp://127.0.0.1:8200");
Client_2:
ZmqDealerSocket dealer = new ZmqDealerSocket();
dealer.Connect("tcp://127.0.0.1:8000");
ZmqSubscribeSocket subscriber = new ZmqSubscribeSocket();
subscriber.Connect("tcp://127.0.0.1:8200");
did i bind it right or ...
|
|
|
|
|
|
hi , i didnt asked my qustion in public bcz i know it takes too much time for getting the result .
i have make an execute program of the project that i has made with visualstadio 2010 .
i have setup it on my windows 7 , and it works fine.
but when im setup it in windows xp it'll give me an error
unable to load Dll 'libzmq' hresult 80070007h , and sth like this
but i have already attach the file libzmq , and why it didnt throw an error in windows 7 ?
should i attach any other dll to my project .
ty for any help .
|
|
|
|
|
It would help to know exactly what was contained in "and sth like this".
I suspect it was a BadImageFormatException beng thrown. The file libzmq.dll is a C++ library and therefore can't be loaded if you compile your project for 'AnyCPU'.
You need to compile for either x86 ot x64 when using C++ libraries, not for AnyCPU.
The version of libzmq.dll that I posted is the x86 version, so you need to compile your project for x86. It'll run on both x86 & x64, but you need to compile for x86.
|
|
|
|
|
i have already set it on X86
the exactly error that the program throw is :
System.DllNotFoundExpection:Unable to load Dll 'libzmq':The specified procedure could not be found.(Exception from HRESULT:0x8007007F)
at ZeroMQ.Interop.zmq_init(Int32_threads)
at ZeroMQ.ZmqSocket..Ctor(int32 type,Nullable 1 context)
at ZeroMQ.ZmqDealerSocket..ctor()
at WindowsFormsApplication2.form1.server()
windowsapplication2 is the namespace for my program and the server is the method that i call it with a threading.
so , any idea ?
|
|
|
|
|
Did you copy libzmq.dll to your bin folder?
Has the XP box got the right version of the .Net framework on it?
|
|
|
|
|
well i have checked the bin Box and i found the dll even when i wanted to build the program (make setup) i have put the file into the dependency so when the program want's to setup on other computer it'll copy all of that dlls (libzmq,zeromq) into the folder .and then i have checked the box in the windows xp , it was there .
and sth more , even your program haven't get executed there .
it throw an error on jim page is like :
System.DllNotFoundExpection:Unable to load Dll 'libzmq':The specified procedure could not be found.(Exception from HRESULT:0x8007007F)
at ZeroMQ.Interop.zmq_init(Int32_threads)
at ZeroMQ.ZmqSocket..Ctor(int32 type,Nullable 1 context)
at ZeroMQ.ZmqDealerSocket..ctor()
at ChatClient.Client.Main(string[] args) in c:\my Development\ZeroMq\ZeroMQ_ChatTest\ChatClient\Client.cs:Line 13
and the line 13 is refer to zmqDealerSocket dealer = new ZmqDealerSocket();
i'll try to download another .netframework .4
|
|
|
|
|
hi again . im sorry for bothering again .
im wondering why you didint use the router class instead of the dealer in the server class ?
im sorry but can you explain alittle about what you done here im new with zeromq but i know the basic , i know that that we need to define a new socket and connect the socket/listen i was doing this in past but now im seeing new things like dealer subscriber and publisher im wondering do they do the same things as the socket is do . but i'll appriciate if you just alittle explain what you done here . ty
|
|
|
|
|
I didn't use the router because it prepends each message with an integer connection ID. I used the client name to identify the client instead.
Honestly, there's not much point me explaining what I've done - my code is minimal. All of the information you need, and more, is in the excellent ZeroMQ documentation. Read the 0MQ Guide - all of the socket patterns are described in great detail in there. Also, looking at the code samples in conjunction with the 0MQ API would help.
I'm sorry if that sounds a bit like RTFM but...
|
|
|
|
|
no , is okay , ty very much . i've learned alot.
i'll figure it out soon or later .
ty again
|
|
|
|
|
hi my friend , im sorry for bothering you again .
just a simple qustion i have .
how should i do sth in the server side dealer.onrecived event . like lets say . close second form in that event(dealer.onrecived) before publisher.send() has executed .
i want to do that but it throw an error and saying :
Cross-thread operation not valid: Control 'Form2' accessed from a thread other than the thread it was created on.
i know that , when im start(run) a method with a thread , i should define a delegate and then invoke the object to access it .
but here i dont know how to access the object .
any help i'll apriciate that .
|
|
|
|
|
This is nothing to do with the question you originally raised, and I'm afraid I've helped you as far as I'm prepared to. I'm not going to write your application for you - it's yours not mine.
One final hint: UI operations from a background thread are not allowed. Both Google and CodeProject will give you more than enough information if you only look.
|
|
|
|
|
how can i solve this problem?
|
|
|
|
|
|
i saw it. but i solve it by Updating the vs 2012.
any way, thanks alot
|
|
|
|
|
Mohamad Shahmardan wrote: thanks alot
You're welcome!
In some cases, my signature will be longer than my message...
<em style="color:red"> <b>ProgramFOX</b></em> ProgramFOX
|
|
|
|
|
in the code i know for shure that i did get the data to my string sqlCity.but when the code come to adap.Fill(dt); it just jump to the catch.i try to do debugging but i did not find the reason why it not fill my dt datatable.can someone tell my what is the problem ?
public partial class test1 : System.Web.UI.Page
{
public SqlConnection myConn;
sqlDataAdapter adap;
public DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
string conn = @"Data Source=.\SQLEXPRESS;AttachDbFilename='"
+ Server.MapPath(@"App_Data\Database.mdf") + "';Integrated Security=True;User Instance=True";
myConn = new SqlConnection(conn);
try
{
myConn.Open();
string sqlCity = "select * from common";
adap = new sqlDataAdapter(sqlCity, myConn);
dt = new DataTable();
adap.Fill(dt);
}
catch
{
MessageBox.Show("Error.....");
}
finally
{
myConn.Close();
}
}
}
|
|
|
|