你们请我需要帮助搞清楚如何使这个桌面应用程序连接到位于另一台使用无线局域网的计算机服务器。应用程序(客户端和服务器)是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}
请人帮我用的方式进行。
感谢在前进。