2
private void btnStart_Click(object sender, EventArgs e)
{
try
{
epLocal = new IPEndPoint(IPAddress.Parse(txtIP1.Text), Convert.ToInt32(txtPort1.Text));
sck.Bind(epLocal);
epRemote = new IPEndPoint(IPAddress.Parse(txtIP2.Text), Convert.ToInt32(txtPort2.Text));
//Here Error Occures I dont know what is my mistake?
sck.Bind(epRemote);
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
btnStart.Text = "Connected";
btnStart.Enabled = false;
btnSend.Enabled = true;
txtMessage.Focus();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
謝謝,在這裏,作爲基層即時連接我自己的IP爲txtIP1和txtIP2:192.168.0.102,端口分別爲91和92。端口可用性由netstat -a命令檢查,它們可用,我很困惑,接下來要嘗試什麼。 – User23289
sck是Socket還是TCPSocket? –
我已經更新了我的回答,這個很好的幫助你 –