This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3200建立的tcp_socket如何能够与C#写的server建立正常链接

Other Parts Discussed in Thread: CC3200

今天看了tcp_socket的demo,想自己写一个C#服务器端,实现双方通信。

按照案列,我看了下bsdclient的函数:

在上面的连接服务器时显示不正确。

我的C#写的服务器端一监听到连接就 发出:

“远程主机强制关闭了一个现有的连接。”

请问这种问题该如何解决?或者说我C#写的server端如何才能与cc3200进行正常通信呢?

附C#服务器代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace SocketServer
{
    class Program
    {
        private static byte[] result = new byte[1024];
        private static int myProt = 5001;   //绔彛
        static Socket serverSocket;
        static void Main(string[] args)
        {
            //鏈嶅姟鍣Arrow upper leftP鍦板潃
            IPAddress ip = IPAddress.Parse("192.168.1.15");
            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            serverSocket.Bind(new IPEndPoint(ip, myProt));  //缁戝畾IP鍦板潃锛氱鍙�
            serverSocket.Listen(10);    //璁惧畾鏈€澶�10涓帓闃熻繛鎺ヨ姹�
            Console.WriteLine("鍚姩鐩戝惉{0}鎴愬姛", serverSocket.LocalEndPoint.ToString());
            //閫氳繃Clientsoket鍙戦€佹暟鎹�
            Thread myThread = new Thread(ListenClientConnect);
            myThread.Start();
            Console.ReadLine();
        }

        /// <summary>
        /// 鐩戝惉瀹㈡埛绔繛鎺�
        /// </summary>
        private static void ListenClientConnect()
        {
            while (true)
            {
                Socket clientSocket = serverSocket.Accept();
                clientSocket.Send(Encoding.ASCII.GetBytes("Server Say Hello"));
                Thread receiveThread = new Thread(ReceiveMessage);
                receiveThread.Start(clientSocket);
            }
        }

        /// <summary>
        /// 鎺ユ敹娑堟伅
        /// </summary>
        /// <param name="clientSocket"></param>
        private static void ReceiveMessage(object clientSocket)
        {
            Socket myClientSocket = (Socket)clientSocket;
            while (true)
            {
                try
                {
                    //閫氳繃clientSocket鎺ユ敹鏁版嵁
                    int receiveNumber = myClientSocket.Receive(result);
                    Console.WriteLine("鎺ユ敹瀹㈡埛绔瘂0}娑堟伅{1}", myClientSocket.RemoteEndPoint.ToString(), Encoding.ASCII.GetString(result, 0, receiveNumber));
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    myClientSocket.Shutdown(SocketShutdown.Both);
                    myClientSocket.Close();
                    break;
                }
            }
        }
    }
}