我正在做一个任务,我需要使用 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);
}
任何的想法?????