problem with client/server application
-
By writing code. Perhaps you need to ask something more specific ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Try creating a TcpListener , listening at a local endpoint and accepting tcp connections TcpListener listener = new TcpListener(YOUR EndPoint here(new LocalEndPoint(....))); listener.Start(); Listener.AcceptTcpConnections... //Wait for new Connection from Client Then at the Client Side you should simply create a TcpClient and connect To a RemoteEndPoint which is what u've created as localEndpoint at your server side, TcpClient tcpc = new TcpClient(remoteEndPoint); then you can send objects to server and obtain responses try http://www.google.com/search?hl=en&source=hp&q=simple+Client+Server+C%23&aq=f&oq=&aqi=
-
By writing code. Perhaps you need to ask something more specific ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
there are 2 systems with ips 192.168.1.87(clientA,serverA) and 192.168.1.35(clientB,serverB) . on both the systems client and server runs. now clientA sends a message to serverB on button click. as soon as serverB recieves a message it should send that message to ClientB how is that possible clientA--->serverB(onmessagerecieved)--->cientB
server:-
int recv;
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 10294);
Socket newsock = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep);
newsock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Any, IPAddress.Parse("127.0.0.1")));while (true)
{
IPEndPoint sender2 = new IPEndPoint(IPAddress.Any, 0);
IPEndPoint sender1 = new IPEndPoint(IPAddress.Parse("192.168.1.35") , 0);
EndPoint tmpRemote = (EndPoint)(sender2);
EndPoint tmpRemote1 = (EndPoint)(sender1);
data = new byte[1024];
recv = newsock.ReceiveFrom(data, ref tmpRemote);
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
string welcome = "7010";
data = Encoding.ASCII.GetBytes(welcome);
newsock.SendTo(data, data.Length, SocketFlags.None, tmpRemote1 );
}client:-
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("192.168.1.35"), 10294);
byte[] data = new byte[1024];
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);private void Form1_Load(object sender, EventArgs e)
{
client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 10);
}
private void button1_Click(object sender, EventArgs e)
{
string welcome = "What's your IP?";
data = Encoding.ASCII.GetBytes(welcome);
client.SendTo(data, data.Length, SocketFlags.None, ipep);
}private void timer1_Tick(object sender, EventArgs e)
{
IPEndPoint server = new IPEndPoint(IPAddress.Any, 0);
EndPoint tmpRemote = (EndPoint)server;
data = new byte[1024];
int recv = client.ReceiveFrom(data, ref tmpRemote);
this.richTextBox1.Text = Encoding.ASCII.GetString(data, 0, recv);
}private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
client.Close();
}