Management Program

M

mac

I've been writing in c# for a little over a year, now. I'm writing a
program that will provide specific remote management functions using
client/admin type interface (a client listener will receive commands
from admin program, perform the command and return necessary
information).

My question is this: What is the best way to transfer data from the
admin program to a client program. TCP? UDP? Sockets? One of my
first programs involved UDP, but I don't know if it was very effective
and I want this program to be solid.

Thank you very much for any input your provide me. It certainly would
be appreciated!

Thanks,
mac
 
D

Diego Jancic

Hi,
UDP is a disconnected protocol, you should use TCP in this case, at
least for the main communications. In .net you can choose work using
Sockets, Remoting or WCF without having a performance fall. Remoting
is a Service-Oriented Framework built over sockets. Windows
Communication Fundation (WCF) is a bigger framework available in .net
3.0 that allow you to works easier. If you need extreme performance
you should probably would use sockets to do the hard work, but it'll
too much hard than using Remoting...
To do some functionality you will need UDP, but it's not in the core
(i.e.: Start up a PC on lan)

Bye,
Diego
 
M

mac

Hi,
UDP is a disconnected protocol, you should use TCP in this case, at
least for the main communications. In .net you can choose work using
Sockets, Remoting or WCF without having a performance fall. Remoting
is a Service-Oriented Framework built over sockets. Windows
Communication Fundation (WCF) is a bigger framework available in .net
3.0 that allow you to works easier. If you need extreme performance
you should probably would use sockets to do the hard work, but it'll
too much hard than using Remoting...
To do some functionality you will need UDP, but it's not in the core
(i.e.: Start up a PC on lan)

Bye,
Diego

Thank you for your response. I'm choosing to use TCP Sockets as you
suggested (mainly because I'm not sure how to use the other ones).
Any pointers or things I should know while I'm writing my TCP
connection?

-mac
 
D

Diego Jancic

No, I don't think there's too much complexity in the connection
itself, but you must divide the objects' responsabilities right to
have good dreams :)
Creating a connection and sending information is easy, a bit harder is
to test the transmition problems when the application is running.
Think earlier in the maintenance work and you'll have no problems

bye.
--- Sorry for my english, did you understood anything?
 
M

mac

No, I don't think there's too much complexity in the connection
itself, but you must divide the objects' responsabilities right to
have good dreams :)
Creating a connection and sending information is easy, a bit harder is
to test the transmition problems when the application is running.
Think earlier in the maintenance work and you'll have no problems

bye.
--- Sorry for my english, did you understood anything?

I'm pretty sure I understand what you're saying here. I found some
code for a Socket connection...I have modified it slightly from what
I'm pasting, is this a good start, though?

public class Socket
{
//our socket
private Socket sock;

//our buffer to receive bytes
private Byte[] buffer;

//ascii encoding for converting bytes to stings, etc
private ASCIIEncoding ascii;

//AsyncCallBack objects for Async Socker usage
private AsyncCallback ConnectCallBack;
private AsyncCallback ReceiveCallBack;
private AsyncCallback SendCallBack;

public Socket()
{
//create socket
sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);

//create a buffer of size 4095
buffer = new Byte[4095];

//create ascii encoding object
ascii = new ASCIIEncoding();

//create async objects to tell which method to go to
when invoked
ConnectCallBack = new
AsyncCallback(sock_ConnectCallBack);
ReceiveCallBack = new
AsyncCallback(sock_ReceiveCallBack);
SendCallBack = new AsyncCallback(sock_SendCallBack);
}


public void Connect(String IP)
{
//parse IP
IPAddress ip = Dns.GetHostEntry(IP).AddressList[0];

//create IPEndPoint from ip and Port
IPEndPoint ep = new IPEndPoint(ip, _Port);

//begin connecting to other user
sock.BeginConnect(ep, ConnectCallBack, null);
}
public void Connect(IPAddress IP)
{
//parse IP
IPAddress ip = Dns.GetHostEntry(IP).AddressList[0];

//create IPEndPoint from ip and Port
IPEndPoint ep = new IPEndPoint(ip, _Port);

//begin connecting to other user
sock.BeginConnect(ep, ConnectCallBack, null);
}


private void sock_ConnectCallBack(IAsyncResult ar)
{
/* finalize the connection and begin receiving
information from
* the user, passing in our AsyncCallBack object
*/
sock.EndConnect(ar);
sock.BeginReceive(buffer, 0, buffer.Length,
SocketFlags.None, ReceiveCallBack, null);
}

private void sock_ReceiveCallBack(IAsyncResult ar)
{
//get the number of bytes received
int numBytes = sock.EndReceive(ar);

/* if numBytes < 1 then other user disconnected from
session,
* so shutdown socket and exit method
*/
if (numBytes < 1)
{
sock.Shutdown(SocketShutdown.Both);

return;
}

//if buffer is null, exit method
if (buffer == null)
return;

/* get string from bytes (can also write the bytes to
a file,
* all bytes received are in the array named buffer)
*/
String str = ascii.GetString(buffer);

/* clear the array so if the array isnt filled next
time,
* we wont have extra info
*/
Array.Clear(buffer, 0, buffer.Length);

//begin received again
sock.BeginReceive(buffer, 0, buffer.Length,
SocketFlags.None, ReceiveCallBack, null);
}


public void Send(Byte[] bt)
{
/* begin sending to connected client, passing our
AsyncDelegate
* telling where to go when the send is complete
*/
sock.BeginSend(bt, 0, bt.Length, SocketFlags.None,
SendCallBack, null);
}


private void sock_SendCallBack(IAsyncResult ar)
{
//handle send finalize here...
sock.EndSend(ar);
}


}

I will be modifying this code to actually send a serialized, encrypted
object to make it a little more secure. Is there any other way to
make the connection itself more secure?

Thank you for your input!
-mac
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top