返回首页

你们请我需要帮助搞清楚如何使这个桌面应用程序连接到位于另一台使用无线局域网的计算机服务器。应用程序(客户端和服务器)是TCP / IP网络方案。
这是从客户端和服务器代码摘录:

从客户端:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

using System.IO;

 

namespace TCP_test_client

{

    public partial class Form1 : Form

    {

        const int buffer = 5000;

        const int port = 1759;

        const string LocalHost = "localhost";

        byte[] incoming = new byte[buffer];

        byte[] outgoing = new byte[buffer];

        

        public Form1()

        {

            InitializeComponent();            

        }

 

        private void connect()

        {

            TcpClient myC = new TcpClient(LocalHost, port);

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            string user = textBox1.Text;

            string pass = textBox2.Text;

            string send = string.Empty;

 

            TcpClient myClient = new TcpClient(LocalHost, port);

            MessageBox.Show("Connected");

 

            send = "login$" + user + "$" + pass;

 

            outgoing = ASCIIEncoding.ASCII.GetBytes(send);

            Stream myStream = myClient.GetStream();

            myStream.Write(outgoing, 0, outgoing.Length);

 

            for (int i = 0; i < incoming.Length; i++)

            {

                incoming[i] = 0;

            }

 

            myStream.Read(incoming, 0, incoming.Length);

            MessageBox.Show(ASCIIEncoding.ASCII.GetString(incoming, 0, incoming.Length));

    

        }

    }

}

从服务器:

{C}
请人帮我用的方式进行。
感谢在前进。

回答

评论会员:理查德MacCutchan 时间:2012/02/07

        const string LocalHost = "localhost";

...

            TcpClient myC = new TcpClient(LocalHost, port);

的尝试连接到服务器,岂不是更好
评论会员:?SAKryukov 时间:2012/02/07
确定,你没有和我们一起分享您的问题是什么,但是这个代码只是看起来不严重。你可以不认真发展离不开线程TCP通信。

你可以从我过去的解决方案的一些想法:]

mdash; SA