客户端:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace GameClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IPAddress serverIp = IPAddress.Parse("127.0.0.1");
string Port = "8001";
IPEndPoint serverhost = new IPEndPoint(serverIp, Int32.Parse(Port));
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
client.Connect(serverhost);
}
catch
{
MessageBox.Show("链接失败");
return;
}
string id = textBox_id.Text;
//string pas = textBox_pas.Text;
// byte[] byteId = Encoding.ASCII.GetBytes(id.ToCharArray());
byte[] byteId = Encoding.GetEncoding("GB2312").GetBytes(id.ToCharArray());
//byte[] bytePas = Encoding.ASCII.GetBytes(pas.ToCharArray());
client.Send(byteId, 0, byteId.Length, SocketFlags.None);
test.Text = Convert.ToString(byteId.Length);
//client.Send(bytePas, 0, bytePas.Length, SocketFlags.None);
client.Close();
}
}
}
  Encoding.GetEncoding("GB2312").GetBytes(id.ToCharArray())和string id = Encoding.GetEncoding("GB2312").GetString(receive, 0, i)可以进行字符字母和文字的传输。
  好多Try,catch没加,只是试验。能把数据传到服务器了,这样可以让服务器从数据库里调数据了,然后再返回给客户端,这样可以做用户验证类似的活动了,而且游戏的数据也可以这样传,我现在是这么想的,不知道真正的大游戏是怎么传的。。。。我没做过。先随便试下。