|
There is more than one way to make client server applications in C#,
u can go for .net remoting technology. u can easily find helping material on net.
this article will help u
www.c-sharpcorner.com/Network/RemotingInNETM.asp
|
|
|
|
|
Hi,
Indeed there are several ways to create an client - server architecture in c#. It only depends on the type of data you want to transmit. If you want data over the Network then you should try using Socket (System.Net.Socket). If you need an example let me know.
Do your best to be the best
|
|
|
|
|
OK
Man provide me the example so i can work it out , thankx in advance
|
|
|
|
|
Well,
It is very important to understand that sockets exchange only byte arrays between them, regardless of what the byte arrays contain (file, string message etc.). So it is very important that when you receive something to know what you receive. At first you should try to create your own communication protocol.
In my example the client send a string message and the server receives it
For the server:
<br />
Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);<br />
m_tcpListener.Bind(new IPEndPoint(IPAddress.Any,10000>));
Socket client = server.Accept();
byte []buffer = new byte[1024];<br />
int read = 0;<br />
string receivedMessage = "";<br />
while ( (read = client.Receive(buffer)) != 0 )<br />
{<br />
receivedMessage = String.Concat(Encoding.ASCII.GetString(buffer),receivedMessage);<br />
if (read < buffer.Length)<br />
break;<br />
}<br />
client.Shutdown(SocketShutdown.Both);<br />
For the client:
<br />
Socket client = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);<br />
client.Connect(new IPEndPoint(Dns.Resolve("127.0.0.1").AddressList[0],10000));<br />
string message = "This is a test";<br />
client.Send(Encoding.ASCII.GetBytes(message));<br />
client.Shutdown(SocketShutdown.Both);<br />
Hope it helps
Do your best to be the best
|
|
|
|
|
Thankx man for ur example when i am using this code snippet of the server it is giving the error on this
m_tcpListener.Bind(new IPEndPoint(IPAddress.Any,10000))
and shows no method of the tcp listener with the name of bind thers is the Server property of TCP Listener which have the method Bind , but its not workin plzzzzzzz, Reply me ASAP,thankx for ur reply.
|
|
|
|
|
Hi,
I must appologise. Please in the server code replace TCPListener with Socket. I confused the server declaration
Do your best to be the best
|
|
|
|
|
...or the easist way if it's sufficient for your purposes is ASP.NET webservices.
Regards,
Rob Philpott.
|
|
|
|
|
Well i don't want to use web services , iknow abt the web services , but i wanna make client Server with out web services, thanks in advance
|
|
|
|
|
hi folks,
i know how to use crystal reports in asp.net with c#. but it connected with only one table at a time but i need to connect different table with single rpt file ,if any one knows about this plz share with me
regards,
ranandbe
|
|
|
|
|
you should create view in database for connect many table a time
|
|
|
|
|
thanx for reply,
plz give me sample code
regards
ranandbe
|
|
|
|
|
Hi,
I am using the following code to encrypt/decrypt a connection string in my app.config file:
private void ProtectConfiguration()<br />
{<br />
<br />
config = ConfigurationManager.OpenExeConfiguration(myGlobalFilePath);<br />
<br />
string provider =<br />
"DataProtectionConfigurationProvider";<br />
<br />
<br />
ConfigurationSection connStrings =<br />
config.ConnectionStrings;<br />
<br />
if (connStrings != null)<br />
{<br />
if (!connStrings.SectionInformation.IsProtected)<br />
{<br />
if (!connStrings.ElementInformation.IsLocked)<br />
{<br />
connStrings.SectionInformation.ProtectSection(provider);<br />
<br />
connStrings.SectionInformation.ForceSave = true;<br />
config.Save(ConfigurationSaveMode.Full);<br />
<br />
Console.WriteLine("Section {0} is now protected by {1}",<br />
connStrings.SectionInformation.Name,<br />
connStrings.SectionInformation.ProtectionProvider.Name);<br />
<br />
}<br />
else<br />
Console.WriteLine(<br />
"Can't protect, section {0} is locked",<br />
connStrings.SectionInformation.Name);<br />
}<br />
else<br />
Console.WriteLine(<br />
"Section {0} is already protected by {1}",<br />
connStrings.SectionInformation.Name,<br />
connStrings.SectionInformation.ProtectionProvider.Name);<br />
<br />
}<br />
else<br />
Console.WriteLine("Can't get the section {0}",<br />
connStrings.SectionInformation.Name);<br />
<br />
}<br />
<br />
<br />
private void UnProtectConfiguration()<br />
{<br />
<br />
config = ConfigurationManager.OpenExeConfiguration(myGlobalFilePath);<br />
<br />
ConfigurationSection connStrings =<br />
config.ConnectionStrings;<br />
<br />
if (connStrings != null)<br />
{<br />
if (connStrings.SectionInformation.IsProtected)<br />
{<br />
if (!connStrings.ElementInformation.IsLocked)<br />
{<br />
connStrings.SectionInformation.UnprotectSection();<br />
<br />
connStrings.SectionInformation.ForceSave = true;<br />
config.Save(ConfigurationSaveMode.Full);<br />
<br />
Console.WriteLine("Section {0} is now unprotected.",<br />
connStrings.SectionInformation.Name);<br />
<br />
}<br />
else<br />
Console.WriteLine(<br />
"Can't unprotect, section {0} is locked",<br />
connStrings.SectionInformation.Name);<br />
}<br />
else<br />
Console.WriteLine(<br />
"Section {0} is already unprotected.",<br />
connStrings.SectionInformation.Name);<br />
<br />
}<br />
else<br />
Console.WriteLine("Can't get the section {0}",<br />
connStrings.SectionInformation.Name);<br />
<br />
}
However whenever I encrypt and decrypt the connectionStrings section of the app.config file, the connection string is not what I entered, it comes out as:
<connectionStrings><br />
<clear /><br />
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"<br />
providerName="System.Data.SqlClient" /><br />
</connectionStrings>
I am trying to encrypt the following connection string:
<connectionStrings><br />
<add name="MyDbName" connectionString="Data Source=MYDBSERVER;Initial Catalog=MYDBNAME;Integrated Security=False;User ID=MYID ; Password=MYPASSWORD" providerName="System.Data.SqlClient"/><br />
</connectionStrings>
Any ideas what I could be doing wrong?
Thank you in advance.
|
|
|
|
|
solved it. was trying to open config file instead of:-> exe
|
|
|
|
|
can anyone tell me, how can i return values from threads in C#?
Reply will be appreciated
Thanx in advance
|
|
|
|
|
You will have to drop the return value in a place that is accessable by another thread. You will have to protect the storage with a mutex, also add a condition to signal the other thread that processing is done. This is needed because processes can't return things to eachother, instead they storage data that has to be exchanged in a central place that is accessable by others.
These two steps start the threads and let the first thread wait for a signal of the other thread.
Thread 1 -> Thread2.Start();
Thread 1 -> Condition.Wait();
These steps are performed by the second thread in such a way that the storage can only be accessed by one party at a time. After the second thread is done, it will signal the first thread that it's done.
Thread 2 -> Mutex.Lock();
Thread 2 -> Set some value
Thread 2 -> Mutex.Unlock();
Thread 2 -> Condition.Signal();
These last steps are performed after the first thread gets a signal that the second thread is done.
Thread 1 -> Mutex.Lock();
Thread 1 -> Get value
Thread 1 -> Mutex.Unlock();
I'm not sure to what extend Microsoft implemented threading and concurrency tools, but if you don't have the Mutex or the Condition, you can do it with a Semaphore. The same trick, except for these changes:
Thread 1 -> Semaphore.P();
Thread 2 -> Set value in storage
Thread 2 -> Semaphore.V();
Thread 1 -> Get value from storage
This classic is also called the producer/consumer scenario.
WM.
What about weapons of mass-construction?
|
|
|
|
|
Hi ,
I'm Working on dataGridView i want the datagridview to scroll to specified row
like if the row # 10 is selected i want to jump to other row like row # 1010
this easy by using dataGridView1.Rows[1010].Selected = true;
but how can i make the dataGridView to scroll to that row
Thx for ur help
Regards,
Charbel
|
|
|
|
|
Hello
MyDataGridView.FirstDisplayedCell = MyDataGridView.Rows[MyIndex].Cells[0];
Sorry! Requires .Net 2.0
Regards
|
|
|
|
|
hi all,
I have a MDIForm, contains a TreeView. I wanna set focus to a child form after I clicked a note.
But, the TreeView doesn't lost foucs. so, my question is:
how to set focus to a child form after I clicked a TreeNode?
and I googled this question, I got this:
<br />
Form newForm = this.CreateForm();
form.BeginInvoke((MethodInvoker)delegate(){form.Focus();});<br />
at MSDN Forums
but it doesn't work.
any help would be appreciate. Thanks.
|
|
|
|
|
I’m coding in C# and I am working with a COM object that I earlier in C++ made this call:
COleVariant varBeforeEnd(DISP_E_MEMBERNOTFOUND, VT_ERROR);<br />
hresult = pTemp->Add(knownObject, &varBeforeEnd );
How do I make the call in C#?
The IDE in VisualStudio say that the Add(…) function should have parameters like this:
Add(KownObject, ref object);
Any tip what to do with the second parameter? I’ve tried to block some primitive types like int and bool to an object, but I only get exceptions…
All tips are welcomed!
_____________________________
...and justice for all
APe
|
|
|
|
|
You have to use the ref keyword when you call the method, and use a variable of type Object to reference:
object o = 42;
Add(knownObject, ref o);
---
b { font-weight: normal; }
|
|
|
|
|
Found the solution:
Object obj = System.Reflection.Missing.Value;<br />
temp.Add(known, ref obj);
_____________________________
...and justice for all
APe
|
|
|
|
|
Hi everybody.
I want to write a full screen app. All that I want is a white dot on a black screen that moves up, down, left, right according to the keyboard.
Its all not complex at all if I would've done that on a window form, BUT I want to make it on a console (or whatever type of project it should be).
The problem is that I don't even know where to start to make such an application, can anyone at least give me directions where do I start? (an article maybe?).
Thanks!
|
|
|
|
|
You could look into a DirectX app. I'm shure there are some articles on this site to help you out with that.
|
|
|
|
|
Hello there,
I'm trying to create a IPCChannel connection between 2 processes on my pc. The 1 process is a Windows Service and the other a Windows app.
The windows service is the client in this case. when doing the connection an exception is thrown saying:Failed to connect to an IPC Port: Access is denied.
When I debug this windows service (run it as a normal app not as a service), the code executes fine. So does anybody why as a Service the app is not allowed to connect and how I might fix this???
Thanks for any help you provide,
Greetings,
Davy
|
|
|
|
|
I'm new to IPC but ...
Have you checked SecurityPermission attribute?
BTW if you know how to detect if IPC channels have been opened by the remote process, could you please tell me ?
|
|
|
|