C# 소켓 예제에서 발생한 에러가 무슨 뜻인지 모르겠습니다.

gomnutu의 이미지

Client 쪽 소스 입니다.

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
 
namespace client
{
    class ClientClass
    {
        public static Socket socket;
        public static byte[] getbyte = new byte[1024];
        public static byte[] setbyte = new byte[1024];
 
        public const int sPort = 8999;
 
        [STAThread]
        static void Main(string[] args)
        {
            string sendstring = null;
            string getstring = null;
 
            IPAddress serverIP = IPAddress.Parse("127.0.0.1");
            IPEndPoint serverEndPoint = new IPEndPoint(serverIP, sPort);
 
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine(" 서버로 접속을 시작합니다.[엔터를 입력하세요]");
            Console.WriteLine("-------------------------------------------------");
            Console.ReadLine();
 
            try
            {
                socket.Connect(serverEndPoint);
 
                if (socket.Connected)
                {
                    Console.WriteLine(">> 정상적으로 연결 되었습니다.(전송한 데이터를 입력해주세요)");
                }
 
                while (true)
                {
                    Console.Write(">>");
                    sendstring = Console.ReadLine();
 
                    if (sendstring != String.Empty)
                    {
                        int getValueLength = 0;
                        setbyte = Encoding.UTF7.GetBytes(sendstring);
                        socket.Send(setbyte, 0, setbyte.Length, SocketFlags.None);
                        Console.WriteLine("송신데이터 : {0}| 길이 : {1}", sendstring, setbyte.Length);
 
                        socket.Receive(getbyte, 0, getbyte.Length, SocketFlags.None);
                        getValueLength = byteArrayDefrag(getbyte);
                        getstring = Encoding.UTF7.GetString(getbyte, 0, getValueLength + 1);
                        Console.WriteLine(">> 수신된 데이터 : {0}| 길이{1}", getstring, getValueLength + 1);
                    }
                    getbyte = new byte[1024];
                }
            }
            catch (System.ArgumentNullException socketEx)
            {
                Console.WriteLine("[Error]:{0}", socketEx.Message);
            }
            catch (System.Exception commonEx)
            {
                Console.WriteLine("[Error]:{0}", commonEx.Message);
            }
        }
        public static int byteArrayDefrag(byte[] sData)
        {
            int endLength = 0;
 
            for (int i = 0; i < sData.Length; i++)
            {
                if((byte)sData[i] != (byte)0)
                {
                    endLength = i;
                }
            }
            return endLength;
        }
    }
}
 
 
 
    /*
    static class Program
    {
        /// <summary>
        /// 해당 응용 프로그램의 주 진입점입니다.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
    }
 */ 

Server 쪽은 잘 돌아가면서 Client가 접속할때까지 기다리는데
Client를 실행하면

[Error]:문자열 참조가 문자열의 인스턴스로 설정되지 않았습니다.
매개 변수 이름: s
'System.ArgumentNullException' 형식의 첫째 예외가 mscorlib.dll에서 발생했습니다.
0x167c 스레드가 종료되었습니다(코드: 0 (0x0)).
0x498 스레드가 종료되었습니다(코드: 0 (0x0)).
'[7452] client.vshost.exe: 관리' 프로그램이 종료되었습니다(코드: 0 (0x0)).

무슨 뜻인지 이해가 안갑니다. 어떤 에러죠?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.