Hi All,
I am new in programming, and currently learning from some samples. From a page, I tried to implement a TCP client server with the following page in WPF (visual studio 2008)
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
public class serv
{
public static void Main()
{
try
{
IPAddress ipAd = IPAddress.Parse("172.21.5.99"); //use local m/c IP address, and use the same in the client
/* Initializes the Listener */
TcpListener myList = new TcpListener(ipAd, 8001);
/* Start Listeneting at the specified port */
myList.Start();
Console.WriteLine("The server is running at port 8001...");
Console.WriteLine("The local End point is :" + myList.LocalEndpoint);
Console.WriteLine("Waiting for a connection.....");
Socket s = myList.AcceptSocket();
Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
byte[] b = new byte[100];
int k = s.Receive(b);
Console.WriteLine("Recieved...");
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(b[i]));
ASCIIEncoding asen = new ASCIIEncoding();
s.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement");
/* clean up */
s.Close();
myList.Stop();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}
However, when I tried to compile it, I got an error,
Error 1 Program 'C:\Users\niub\Documents\Visual Studio 2008\Projects\WpfApplication5\WpfApplication5\obj\Debug\WpfApplication5.exe' has more than one entry point defined: 'WpfApplication5.App.Main()'. Compile with /main to specify the type that contains the entry point. C:\Users\niub\Documents\Visual Studio 2008\Projects\WpfApplication5\WpfApplication5\obj\Debug\App.g.cs 59 28 WpfApplication5
I know this is because there is another main in a file (which is strangely auto-generated) . I tried to delete this App.g.cs auto generated class, and it removed the error (but yet, my source sample code didn't show anything .. strangely :( )
Below is what is inside the App.g.cs :
#pragma checksum "..\..\App.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "DC57595DE0B4DB627E16D0F860D8BC4C"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3053
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication5 {
/// <summary>
/// App
/// </summary>
public partial class App : System.Windows.Application {
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent() {
#line 4 "..\..\App.xaml"
this.StartupUri = new System.Uri("Window1.xaml", System.UriKind.Relative);
#line default
#line hidden
}
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public static void Main() {
WpfApplication5.App app = new WpfApplication5.App();
app.InitializeComponent();
app.Run();
}
}
}
Can any of you help me to solve this problem, and try to give me a about this strangely autogenerated file?
Thank you