简体   繁体   English

编译程序时出错

[英]Error when compiling program

I made a client server but unfortunately I get this error 我做了一个客户端服务器,但是不幸的是我得到了这个错误

You can tell me how to fix it please? 你能告诉我如何解决吗?

The error occurs in class client.cs ... It's written right IP? 该错误发生在类client.cs中...它是正确的IP吗?

I opened the command prompt and wrote "ipconfig" and the number of IPv4 there is "192.168.1.104" 我打开命令提示符并输入“ ipconfig”,IPv4的数量为“ 192.168.1.104”

Client.cs Client.cs

 try
        {
            TcpClient tcp = new TcpClient();
            Console.WriteLine("Conectare...");

            tcp.Connect("192.168.1.104", 8001);
            Console.WriteLine("Conectat");
            Console.WriteLine("Introduce-ti sirul de caractere");
            string str = Console.ReadLine();
            Stream strm = tcp.GetStream();

            ASCIIEncoding asci = new ASCIIEncoding();
            byte[] ba = asci.GetBytes(str);
            Console.WriteLine("Trimitere");
            strm.Write(ba, 0, ba.Length);

            byte[] bb = new byte[100];
            int b = strm.Read(bb, 0, 100);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Eroare..."+ex.StackTrace);

        }

Server.cs Server.cs

 try
        {
            IPAddress IPadress = IPAddress.Parse("192.168.1.104");
            TcpListener listner = new TcpListener(IPadress, 8001);
            Console.WriteLine("Serverul ruleaza");
            Console.WriteLine("Punctul final este: " + listner.LocalEndpoint);
            listner.Start();
            Socket o = listner.AcceptSocket();
            Console.WriteLine("Conexiunea acceptata de la " + o.RemoteEndPoint);
            byte[] b = new byte[100];
            int k = o.Receive(b);
            Console.WriteLine("Receptionat");
            for (int i = 0; i < k; i++)
            {
                Console.WriteLine(Convert.ToChar(b[1]));
            }
            ASCIIEncoding asc = new ASCIIEncoding();
            o.Send(asc.GetBytes("Mesaj automat" + "String trimis de server"));
            o.Close();
            listner.Stop();
        }
        catch (Exception ex)
        {

            Console.WriteLine("Measj de eroare" + ex.StackTrace);
        }
        Console.ReadLine();

http://i62.tinypic.com/2zj9uop.jpg http://i62.tinypic.com/2zj9uop.jpg

Go to www.google.com and type "what is my ip", the first result you will see will be your real ip. 转到www.google.com并键入“ what is my ip”,您将看到的第一个结果将是您的真实IP。 Now to be able to connect to that IP from an external application you must allow your 'own IP' to the whitelist from your router website page. 现在,要能够从外部应用程序连接到该IP,您必须允许您的“自己的IP”从路由器网站页面进入白名单。 A simillar page to this http://www.theninjaproxy.org/wp-content/uploads/2013/07/netgearWNDR4500.jpg . http://www.theninjaproxy.org/wp-content/uploads/2013/07/netgearWNDR4500.jpg的相似页面。 If you wanted to open that application from your friends computer who has another IP lets say '11.11.11.11' you need to add that too or else he wont be able to open your c# application. 如果您想从拥有另一个IP的朋友计算机上打开该应用程序,并说“ 11.11.11.11”,则也需要添加该内容,否则他将无法打开您的c#应用程序。

Edit: its kind of the same situation where you are trying to connect to a mysql database from ac# application and you have to go to your cpanel and allow the IP of the computer that is using that c# application. 编辑:类似的情况,您试图从ac#应用程序连接到mysql数据库,并且您必须转到cpanel并允许使用该c#应用程序的计算机的IP。 but for you , you simply go to your router webpage. 但是对于您来说,您只需转到路由器网页即可。

Server need to listen in loop to accept client connections. 服务器需要监听循环以接受客户端连接。 Example code 范例程式码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM