【发布时间】:2013-03-11 07:00:48
【问题描述】:
我正在做一个任务,我需要使用 XNA 开发机器人环境并使用来自另一台计算机的 c# TCP/IP 套接字技术控制机器人。但是,当我将服务器代码插入 XNA 时,它会启动,但无法加载游戏。
protected override void Update(GameTime gameTime)
{
//Server Settings
ipAddress = IPAddress.Parse("192.168.0.11");
myList = new TcpListener(ipAddress, 8000);
myList.Start();
s = myList.AcceptSocket();
b = new byte[100];
int? k = s.Receive(b);
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (Keyboard.GetState().IsKeyDown(Keys.Right))
//if (k != null)
myRectangle.X += 3;
if (Keyboard.GetState().IsKeyDown(Keys.Left))
myRectangle.X -= 3;
if (Keyboard.GetState().IsKeyDown(Keys.Up))
myRectangle.Y -= 3;
if (Keyboard.GetState().IsKeyDown(Keys.Down))
myRectangle.Y += 3;
//Screen Boundries
if (myRectangle.X <= 0)
myRectangle.X = 0;
if (myRectangle.X + myTexture.Width >= screenWidth)
myRectangle.X = screenWidth - myTexture.Width;
if (myRectangle.Y <= 0)
myRectangle.Y = 0;
s.Close();
myList.Stop();
base.Update(gameTime);
}
有什么想法吗??????
【问题讨论】:
-
您遇到了什么错误?您是否尝试过单步执行代码?
-
是的。我试过了,我没有收到任何错误,但什么也没发生
标签: c# sockets tcp xna tcpclient