RSS

Monthly Archives: March 2012

.NET Remoting – Server Activated Single Call

Create an object for each request of single client or multiple clients. This is stateless

Server Application

Student.cs

[Serializable]
public class Student
{
public int stuId;
public string stuName;
public int total;
public float avg;

}

GradeApp.cs

public class GradeApp : MarshalByRefObject
{
public GradeApp()
{
Console.WriteLine("A new client connected");
}

public float calcAvg(int total)
{
return total / 8;
}
public Student getAvg(int total)
{
Student s = new Student();
s.avg = calcAvg(total);
return s;
}
}

Program.cs

TcpChannel tcp = new TcpChannel(8001);
ChannelServices.RegisterChannel(tcp,false);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(GradeApp),"server",WellKnownObjectMode.SingleCall);
Console.ReadKey();

Client Application

Program.cs

TcpChannel tcp = new TcpChannel(0);
ChannelServices.RegisterChannel(tcp, false);

string url = "tcp://localhost:8001/server";
RemotingConfiguration.RegisterWellKnownClientType(typeof(GradeApp),url);

GradeApp ga = new GradeApp();
Student st1 =  ga.getAvg(756);
Console.WriteLine("Average is : " + st1.avg;)
Console.WriteLine("Average is : " + st1.avg;)
Student st2 = ga.getAvg(746);
Console.WriteLine("Average is : " + st2.avg);
Console.ReadKey();
 
Leave a comment

Posted by on March 21, 2012 in C#.Net

 

Tags: , ,

.NET Remoting – Server Activated Singleton

Use the same   object for every client. This is statefull.

Server Application

Student.cs

[Serializable]
public class Student
{
public int stuId;
public string stuName;
public int total;
public float avg;

}

GradeApp.cs

public class GradeApp : MarshalByRefObject
{
public GradeApp()
{
Console.WriteLine("A new client connected");
}

public float calcAvg(int total)
{
return total / 8;
}
public Student getAvg(int total)
{
Student s = new Student();
s.avg = calcAvg(total);
return s;
}
}

Program.cs

TcpChannel tcp = new TcpChannel(8001);
ChannelServices.RegisterChannel(tcp,false);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(GradeApp),"server",WellKnownObjectMode.Singleton);
Console.ReadKey();

Client Application

Program.cs

TcpChannel tcp = new TcpChannel(0);
ChannelServices.RegisterChannel(tcp, false);

string url = "tcp://localhost:8001/server";
RemotingConfiguration.RegisterWellKnownClientType(typeof(GradeApp),url);

GradeApp ga = new GradeApp();
Student st1 =  ga.getAvg(756);
Console.WriteLine("Average is : " + st1.avg;)

Student st2 = ga.getAvg(746);
Console.WriteLine("Average is : " + st2.avg);
Console.ReadKey();
 
Leave a comment

Posted by on March 21, 2012 in C#.Net

 

Tags: , ,

.NET Remoting – Client Activated Objects

Create an object for each client. Use the same object for multiple requests from the same client.

Server Application

Student.cs

[Serializable]
public class Student
{
public int stuId;
public string stuName;
public int total;
public float avg;

}

GradeApp.cs

public class GradeApp : MarshalByRefObject
{
public GradeApp()
{
Console.WriteLine("A new client connected");
}

public float calcAvg(int total)
{
return total / 8;
}
public Student getAvg(int total)
{
Student s = new Student();
s.avg = calcAvg(total);
return s;
}
}

Program.cs

TcpChannel tcp = new TcpChannel(8001);
ChannelServices.RegisterChannel(tcp,false);

RemotingConfiguration.RegisterActivatedServiceType(typeof(GradeApp));
Console.ReadKey();

Client Application

Program.cs

TcpChannel tcp = new TcpChannel(0);
ChannelServices.RegisterChannel(tcp, false);

 string url = "tcp://localhost:8001";
RemotingConfiguration.RegisterActivatedClientType(typeof(GradeApp),url);

GradeApp ga = new GradeApp();
 Student st1 =  ga.getAvg(756);
Console.WriteLine("Average is : " + st1.avg);
 
Leave a comment

Posted by on March 21, 2012 in C#.Net

 

Tags: , ,

PHP User Class

<?php
class User
{
private $user_id;
private $username;
private $password;
private $email;
protected static $table_name="lbs_user";

public function __construct($username="",$password="",$email="")
{
$this->username = $username;
$this->password = $password;
$this->email    = $email;
}

/* Add a new user.
* Returns true on success, false on error */

public function getUserId()
{
return  $this->user_id;
}

public function create()
{
global $gdbObj;
$username = $gdbObj->escape_value($this->username);
$password = $gdbObj->escape_value($this->password);
$email    = $gdbObj->escape_value($this->email);

$sql = "INSERT INTO ".self::$table_name." (username,password,email) values('$username','$password','$email')";
if($gdbObj->query($sql))
{
$this->user_id = $gdbObj->insert_id();
return true;
}
else
{
return false;
}

}

/* Update user profile.
* Returns true on success, false on error */
public function update()
{

}

/* Remove an user.
* Returns true on success, false on error */
public function delete()
{

}

}
$guserObj = new User();
?>


 
1 Comment

Posted by on March 18, 2012 in OOP, PHP

 

Tags: