I am using C# remoting for accessing a Label on the server system and the text of that label is to be changed by the click of a button on the client system. I have made a remotable object in a class library naming RemoteObject and added the reference of this class library to both client and server system but when debugging both the server system and client system I am getting the exception "Only one usage of each socket address (protocol/network address/port) is normally permitted"
Please help me in this to rectify this issue..
RemotableObject.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace RemoteObject
{
public class Class1 : MarshalByRefObject
{
public Class1()
{
}
public void setText()
{
ServerClass bs = new ServerClass();
Label lbl = bs.Controls["label1"] as Label;
lbl.Text = "New Text";
}
}
}
Server Side Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RemoteObject;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Server
{
public partial class ServerClass : Form
{
private Class1 myremoteobject;
public ServerClass()
{
InitializeComponent();
myremoteobject = new Class1();
TcpChannel channel = new TcpChannel(30000);
ChannelServices.RegisterChannel(channel, true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Class1), "CSBU", WellKnownObjectMode.SingleCall);
}
}
}
Client Side Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RemoteObject;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Client
{
public partial class ClientClass : Form
{
private Class1 remoteobject = new Class1();
public ClientClass()
{
InitializeComponent();
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan,true);
remoteobject = (Class1)Activator.GetObject(typeof(Class1), "tcp://localhost:30000/CSBU");
}
private void changeTextBtn_Click(object sender, EventArgs e)
{
remoteobject.setText();
}
}
}
Please someone help me with the solution for this exception asap.