Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
<pre lang="c#">
client code


try
{
Process pdf = new Process();
pdf.StartInfo.FileName = @"C:\Users\PC\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\webs\webs\serverservice\serverservice\bin\Debug\serverservice.exe";


serverservice ss = new serverservice();
ss.myserver();


Program pp = new Program();
pp.beet();

}
catch (Exception e)
{
Console.WriteLine("error...." + e.StackTrace);
}
}

public void beet()
{

TcpClient tcpc = new TcpClient();
Console.WriteLine("connecting.......");
tcpc.Connect("10.128.1.116", 80);
Console.WriteLine("connected........");
Console.Write("enter msg to be transimitt");




string str = Console.ReadLine();
Stream stm = tcpc.GetStream();
ASCIIEncoding asc = new ASCIIEncoding();
byte[] ba = asc.GetBytes(str);
Console.WriteLine("transmitting..........");
stm.Write(ba, 0, ba.Length);
byte[] bb = new byte[100];

int k = stm.Read(bb, 0, 100);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(bb[i]));
tcpc.Close();

}





windows service code



protected override void OnStart(string[] args)
{

Thread mythread = new Thread(new ThreadStart(myserver));
mythread.Start();
//Process pdf1 = new Process();
//pdf1.StartInfo.FileName = @"C:\Users\PC\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\webs\webs\clientconsole\clientconsole\bin\Debug\clientconsole.exe";
//pdf1.Start();

}



public void myserver()
{
char d;


IPAddress ipad1 = IPAddress.Parse("10.128.1.116");
TcpListener mylist1 = new TcpListener(ipad1, 80);
mylist1.Start();

Console.WriteLine("server is running at port 80");
Console.WriteLine("local end point is" + mylist1.LocalEndpoint);
Console.WriteLine("waiting for connection");

// ServiceController ser=new
Socket s = mylist1.AcceptSocket();

Console.WriteLine("connection is accepted from" + s.RemoteEndPoint);
byte[] b = new byte[100];
int k = s.Receive(b);
Console.WriteLine("received");

for (int i = 0; i < k; i++)
{
d = Convert.ToChar(b[i]);
Console.Write(char.ToUpper(d));
}

ASCIIEncoding asc = new ASCIIEncoding();
s.Send(asc.GetBytes("msg is recveived"));
Console.WriteLine("\n send aknwldge");
s.Close();
mylist1.Stop();
Console.ReadLine();



}

protected override void OnStop()
{
EventLog.WriteEntry("stopped");
}
}
}
Posted
Comments
Sergey Alexandrovich Kryukov 10-Mar-14 3:05am    
Not a real question, just code dump, not properly formatted. Any concerns? What is the problem?
—SA
Bernhard Hiller 10-Mar-14 3:17am    
Do you have problems finding out the end of a message at the receiver site? Soemthing else?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900