[問題] 請問一下C#的問題

看板C_Sharp (C#)作者 (小呆)時間20年前 (2005/03/20 21:03), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
我用C#寫了個client and server架構的程式 撰寫環境是visual studio .net 2003 然後server可以正確的執行 但是client卻無法連進去(Connect時 出現問題) 我實在是不知道問題出在哪 以下是client的程式碼 server 的ip是0.0.0.0 port是5150 請教諸位高手了.... ------------------------------------------- using System; using System.Text; using System.Net; using System.Net.Sockets; class DataTimeClient { private static IPEndPoint dateTimeHost; public static void Main() { String hostIPString = "0.0.0.0"; String hostPortString = "5150"; IPAddress hostIP = IPAddress.Parse(hostIPString); int hostPort = Int32.Parse(hostPortString); try { dateTimeHost = new IPEndPoint(hostIP, hostPort); } catch (ArgumentException e) { Console.WriteLine("Invalid port number!!"); Console.WriteLine(e.ToString()); String tmp1 = Console.ReadLine(); return; } Socket conn = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { conn.Connect(dateTimeHost); } catch (SocketException se) { Console.WriteLine("Could not establish the connect!!!"); Console.WriteLine(se.ToString()); String tmp2 = Console.ReadLine(); return; } int bytes = 0; Byte[] RecvBytes = new Byte[256]; String RecvString = ""; bytes = conn.Receive(RecvBytes, RecvBytes.Length, 0); RecvString = Encoding.ASCII.GetString(RecvBytes, 0, bytes); Console.WriteLine(RecvString); conn.Shutdown(SocketShutdown.Both); conn.Close(); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.184.161.37
文章代碼(AID): #12FNIMTr (C_Sharp)
文章代碼(AID): #12FNIMTr (C_Sharp)