|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
نويسنده |
پيغام |
Parham متخصص ساخت بازی
تاريخ عضويت: 4 شنبه 28 دي 1390 تعداد ارسالها: 408 محل سكونت: somewhere behind a lot of troubles...
3 شنبه 31 مرداد 1391 - 11:06 |
|
|
آقا من این سورس رو با لوپ بک تست کردم جواب داد...
دوباره تغییرش دادم به اینترنت وصل شدم و جفتشون رو اجرا کردم بازم جواب داد.
اما وقتی کلاینت رو باسه یکی فرستادم و با هم اجرا کردیم برنامه اون ارور می داد که نمی تونه وصل شه و برنامه من تغییری نمی کرد(برنامه سرور رو می گم)
Server code:
كد: |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ChatServerV1
{
class Program
{
static void Main(string[] args)
{
int recv;
byte[] data = new byte[2048];
IPHostEntry siphe=Dns.GetHostByName(Dns.GetHostName());
IPEndPoint ipep = new IPEndPoint(siphe.AddressList[0], 8000);
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Console.WriteLine("Initializing Program and Networking... .");
Console.WriteLine(siphe.AddressList[0]);
server.Bind(ipep);
server.Listen(20);
Console.WriteLine("Waiting for a client... .");
Socket client = server.Accept();
IPEndPoint Clientep = (IPEndPoint)client.RemoteEndPoint;
IPHostEntry iphe=Dns.GetHostEntry(Clientep.Address);
Console.WriteLine("Connected To IP Address {0} at Port {1} .", Clientep.Address, Clientep.Port);
Console.WriteLine("The Client's Computer's Name's {0} .", iphe.HostName);
Console.WriteLine();
Console.WriteLine("Type Your Sentences to show to client...:\n");
while(true)
{
try
{
client.Send(Encoding.ASCII.GetBytes(Console.ReadLine()));
recv = client.Receive(data);
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
data = new byte[2048];
}
catch (SocketException e)
{
Console.WriteLine("Client Has Disconnected...press any key.");
Console.ReadKey();
return;
}
}
Console.WriteLine("Client Disconnected... .");
Console.ReadKey();
client.Close();
server.Close();
return;
}
}
}
|
Client Code:
كد: |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ChatClientV1
{
class Program
{
static void Main(string[] args)
{
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("78.38.83.166"), 8000);
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
int recv;
byte[] data = new byte[2048];
Console.WriteLine("Initializing And Connecting To Server... .");
try
{
server.Connect(ipep);
}
catch (SocketException sckEx)
{
Console.WriteLine("Cannot Connect To Server...Try again at a same time later... .");
Console.ReadKey();
return;
}
Console.WriteLine("You have Connected To server correctly... .Please wait for a message from server.");
while (true)
{
try
{
recv = server.Receive(data);
if (!Commanding(Encoding.ASCII.GetString(data, 0, recv)))
{
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
data = new byte[2048];
server.Send(Encoding.ASCII.GetBytes(Console.ReadLine()));
}
else
{
server.Send(Encoding.ASCII.GetBytes("Again."));
}
}
catch (SocketException e)
{
Console.WriteLine("Server Has Disconnected...press any key.");
Console.ReadKey();
return;
}
}
}
static bool Commanding(string inpd)
{
switch (inpd)
{
case "@1":
System.Diagnostics.Process.Start("C:\\Windows\\write.exe");
return true;
break;
case "@2":
System.Diagnostics.Process.Start("C:\\Windows\\winhlp32.exe");
return true;
break;
case "@3":
System.Diagnostics.Process.Start("C:\\Windows\\System32\\Bubbles.scr");
return true;
break;
case "@4":
System.Diagnostics.Process.Start("C:\\Windows\\System32\\calc.exe");
return true;
break;
case "@5":
System.Diagnostics.Process.Start("C:\\Windows\\System32\\cmd.exe");
return true;
break;
default:
return false;
break;
}
}
}
}
|
لطفا راهنمایی نمایید این طفل ماجراجو را! |
_________________ برای رسیدن به موفقیت آسانسوری وجود ندارد،باید پله پله بالا رفت؛ |
|
بازگشت به بالا |
|
|
|
|
|
|
|
|
صفحه 2 از 3 |
تمام ساعات و تاريخها بر حسب 3.5+ ساعت گرينويچ مي باشد برو به صفحه قبلي 1, 2, 3 بعدي
|
|
شما نمي توانيد در اين انجمن نامه ارسال كنيد. شما نمي توانيد به موضوعات اين انجمن پاسخ دهيد شما نمي توانيد نامه هاي ارسالي خود را در اين انجمن ويرايش كنيد شما نمي توانيد نامه هاي ارسالي خود را در اين انجمن حذف كنيد شما نمي توانيد در نظر سنجي هاي اين انجمن شركت كنيد
|
|
|