Create an object for each request of single client or multiple clients. This is stateless
Server Application
Student.cs
[sourcecode language="csharp"]
[Serializable]
public class Student
{
public int stuId;
public string stuName;
public int total;
public float avg;
}
[/sourcecode]
GradeApp.cs
[sourcecode language="csharp"]
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;
}
}
[/sourcecode]
Program.cs
[sourcecode language="csharp"]
TcpChannel tcp = new TcpChannel(8001);
ChannelServices.RegisterChannel(tcp,false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(GradeApp),"server",WellKnownObjectMode.SingleCall);
Console.ReadKey();
[/sourcecode]
Client Application
Program.cs
[sourcecode language="csharp"]
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();
[/sourcecode]
Subscribe to:
Post Comments (Atom)
How to enable CORS in Laravel 5
https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...
-
< Requirements Java Development Kit (JDK) NetBeans IDE Apache Axis 2 Apache Tomcat Server Main Topics Setup Development Environ...
-
Download Sourcecode [sourcecode language="csharp"] using System; using System.Collections.Generic; using System.Linq; using System...
No comments:
Post a Comment