作者Arton0306 (没有怎麽办)
看板C_Sharp
标题Re: [问题] Socket的accept
时间Sun Dec 10 12:07:09 2006
现在我产生thread来accept
因为要新弄一个物件
我把两个textbox当做新物件的private member
我程式码中的Server is Ready...可以传到client了
但是client传回来的字要显示在textbox时
会有错误说建textbox的thread 和我这个thread不一样
也就是我下面try里面有comment的那一行会出错
要写一个简单的两人互传文字的小程式还真是困难重重@"@
class dealoneconnect{
public dealoneconnect(Socket mainsocket, TextBox inputbox, TextBox
outputbox)
{
foruser = mainsocket;
this.outputbox = outputbox;
this.inputbox = inputbox;
}
public void work(){
Socket clientSocket = foruser.Accept();
String msg="Server is Ready...";
clientSocket.Send(Encoding.ASCII.GetBytes(msg));
byte [] cometext=new byte[1024];
while (true) {
try
{
if (clientSocket.Receive(cometext) != 0)
//outputbox.Text = Encoding.ASCII.GetString(cometext);
}
catch (SocketException ex) {
outputbox.Text = ex.ToString();
}
}
}
private Socket foruser;
private TextBox outputbox;
private TextBox inputbox;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.58.5.192
1F:→ Arton0306:我找到相关文件了~~ 12/10 12:36
写是写出来了 不过还不是很懂...
private void SetText(string text) {
if (this.receiveBox.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, text);
}
else {
this.receiveBox.Text += "\r\n" + text;
}
}
(我的outputbox改成receiveBox)
this.Invoke是怎麽叫
产生receiveBox的thread来把text载入呢??
※ 编辑: Arton0306 来自: 210.58.5.192 (12/10 19:00)
※ 编辑: Arton0306 来自: 210.58.5.192 (12/10 19:01)