Actually i had developed client server one-way commucation.it's working fine after that
i had developed two-way communcation.i will explain one-way and two-way communcation
For suppose client send one Request(message) like "HI" then server listening the request
and it's shows "Hi" measge on server side then at the time server not responding client
request.it's only take user request show on server side only.this is one-way
communcation but whenever server responding for client request like "Hello" then called
two-way communcation.
my project not working two-way communication.really tell u
minium it's not working one-way communcation(client request will not send to server)
in my project also.
clientside udp socket program code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
namespace clientserver1
{
class chart1
{
private static System.Threading.Thread clientThread;
static void Main(string[] args)
{
CreateThreads();
}
private static void CreateThreads()
{
clientThread = new System.Threading.Thread(new
System.Threading.ThreadStart(RunClientThread));
clientThread.Start();
}
private static void RunClientThread()
{
string sendStr = "";
UdpClient theClient = new UdpClient("192.168.0.5",9050);
while (!sendStr.Trim().ToUpper().Equals("END"))
{
sendStr = Console.ReadLine();
byte[] myData = new byte[1024];
myData = Encoding.ASCII.GetBytes(sendStr);
theClient.Send(myData, myData.Length);
}
theClient.Close();
}
private static void RunServerThread()
{
string rcvData = "";
IPEndPoint IPEP = new IPEndPoint(IPAddress.Any, 9050);
UdpClient theSock = new UdpClient(IPEP);
IPEndPoint fromClient;
while (!rcvData.Trim().ToUpper().Equals("END"))
{
byte[] myData = new byte[1024];
fromClient = new IPEndPoint(IPAddress.Any, 0);
myData = theSock.Receive(ref fromClient);
rcvData = Encoding.ASCII.GetString(myData);
Console.WriteLine(fromClient.ToString() + " " + rcvData);
}
theSock.Close();
}
}
}
serverside udp socket program code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
namespace ClientServer_2
{
class chart2
{
private static System.Threading.Thread clientThread;
static void Main(string[] args)
{
CreateThreads();
}
private static void CreateThreads()
{
clientThread = new System.Threading.Thread(new
System.Threading.ThreadStart(RunServerThread));
clientThread.Start();
}
private static void RunClientThread()
{
string sendStr = "";
UdpClient theClient = new UdpClient("192.168.0.5",9050);
while (!sendStr.Trim().ToUpper().Equals("END"))
{
sendStr = Console.ReadLine();
byte[] myData = new byte[1024];
myData = Encoding.ASCII.GetBytes(sendStr);
theClient.Send(myData, myData.Length);
}
theClient.Close();
}
private static void RunServerThread()
{
string rcvData = "";
IPEndPoint IPEP = new IPEndPoint(IPAddress.Any, 9050);
UdpClient theSock = new UdpClient(IPEP);
IPEndPoint fromClient;
while (!rcvData.Trim().ToUpper().Equals("END"))
{
byte[] myData = new byte[1024];
fromClient = new IPEndPoint(IPAddress.Any, 0);
myData = theSock.Receive(ref fromClient);
rcvData = Encoding.ASCII.GetString(myData);
Console.WriteLine(fromClient.ToString() + " " + rcvData);
}
theSock.Close();
}
}
}
above both applications are running same machine
clientside udp socket program and serverside udp socket program are same due to both
applications are runing on same machine.if the applications are running on different
machines then The source code will be identical except for IP address specified in the
RunClientThread( ) in serverside udp socket program.i think my code is correct.if any
wrong logic will be there pls modify the code.
if u want to any reference(not .dll) to the project .pls tell me ur mailid. i will
forward the client-server pdf.i had developed the project based on client-server pdf
can u please solve me for two-way communcation?
thank u.