小白一枚~
这是我做的一个简单的聊天程序,本来是自己写了个服务器代码的,连接没有问题,但是我尝试连接阿里云服务器(今天中午买的)时,出现了连接不上的问题
我的客户端代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
TcpClient tcpClient;
private void button2_Click(object sender, EventArgs e)
{
tcpClient = new TcpClient();
try
{
tcpClient.Connect(this.textBoxIP.Text, Convert.ToInt32(this.textBoxPort.Text));
this.textBoxInfo.Text = "连接成功";
}
catch (Exception ex)
{
MessageBox.Show("连接失败" + ex.Message);
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string message = this.textBoxinput.Text;
this.textBoxInfo.Text = "发送“" + message + "”-" + DateTime.Now.ToShortTimeString() + "\r\n" + this.textBoxInfo.Text;
NetworkStream stream = tcpClient.GetStream();
byte[] byteArray = Encoding.Unicode.GetBytes(message);
stream.Write(byteArray, 0, byteArray.Length);//发送了字节数组
}
}
}
问一下有没有什么办法解决?主要的问题应该是连不上阿里云服务器,我用WINDOWS远程连接可以接上阿里云,但就是用这个客户端连不上。