有人能说出这个观点有什么问题吗? [英] Can anybody tell whats wrong with the argument?
本文介绍了有人能说出这个观点有什么问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码,我试图摆脱代码文本中标记为粗体的红色花线. ." src ="https://social.msdn.microsoft.com/Forums/getfile/965377">
Here is the code and I am trying to get rid of the red squiggle line that is marked bold in the code text.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
namespace ChatMessenger
{
public partial class Form1 : Form
{
Socket sck;
EndPoint epLocal, epRemote;
byte[] buffer;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//set up socket
sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
//get user IP
IP_tbx.Text = GetLocalIP();
remIP_tbx.Text = GetLocalIP();
}
private void connect_btn_Click(object sender, EventArgs e)
{
//binding socket connection
epLocal = new IPEndPoint(IPAddress.Parse(IP_tbx.Text), Convert.ToInt32(localPort_tbx.Text));
sck.Bind(epLocal);
//connect to the user remote IP
epLocal = new IPEndPoint(IPAddress.Parse(remIP_tbx.Text), Convert.ToInt32(remPort_tbx.Text));
sck.Connect(epRemote);
//Listenign the specific port
buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
}
private void MessageCallBack(IAsyncResult aResult)
{
try
{
byte[] receivedData = new byte[1500];
receivedData = (byte[])aResult.AsyncState;
//Converts byte to string
ASCIIEncoding aEncoding = new ASCIIEncoding();
string receivedMessaage = aEncoding.GetString(receivedData);
//Adding the bytes to the message box
message_box.Items.Add("Friend: " + receivedMessaage);
buffer = new byte[1500];
sck.BeginReceive(buffer, 0,buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void send_btn_Click(object sender, EventArgs e)
{
//Convert string to byte
ASCIIEncoding aEncoding = new ASCIIEncoding();
byte[] sendingMessage = new byte[1500];
sendingMessage = aEncoding.GetBytes(message_box.Text);
//Sending the encoded message
sck.Send(sendingMessage);
//add to the list
message_box.Items.Add("me: " + ChatBox_tbx.Text);
}
private string GetLocalIP()
{
IPHostEntry host;
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
return ip.ToString();
}
return "127.0.0.1";
}
}
}
推荐答案
sck.BeginReceive(buffer, 0,buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
您是否尝试过使用"out"按钮关键字?
... out ref epRemote ...
Have you tried it with the "out" keyword?
... out ref epRemote ...
或:
...退出epRemote ...
Or:
... out epRemote ...
-韦恩
这篇关于有人能说出这个观点有什么问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文