?? program.cs
字號(hào):
using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using JLL.SGIP;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要說明。
/// </summary>
class SgipTest
{
/// <summary>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Socket test = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
test.Close();
if (test == null)
{
}
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
EndPoint hostEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8801);
s.Connect(hostEP);
try
{
Bind bind = new Bind();
bind.LoginName = "hello";
bind.LoginPassword = "pwd";
bind.LoginType = 1;
Command cmd = Command.CreateCommand(bind);
s.Send(cmd.GetBytes());
byte[] obj = new byte[1024];
s.Receive(obj);
Bind_Resp bind_resp = (Bind_Resp)Command.ToCommand(obj, 0).Body;
if (bind_resp.Result == 0)
{
Console.WriteLine("ok, connected to server!");
System.Threading.Thread.Sleep(1000);
}
/*
Unbind ubind = new Unbind();
cmd = Command.CreateCommand(ubind);
s.Send(cmd.GetBytes());
s.Receive(obj);
Unbind_Resp ubind_resp = (Unbind_Resp)Command.ToCommand(obj, 0).Body;
*/
Console.WriteLine("waiting for server (150 second)...........");
try
{
byte[] buff = new byte[1024];
s.ReceiveTimeout = 150000;
int nRead = s.Receive(buff);
if (nRead == 0)
{
Console.WriteLine("server had shutdown!");
}
else
{
Console.WriteLine("ok, Server disconnected the socket. received data from server!");
try
{
cmd = Command.ToCommand(buff, 0);
Console.WriteLine("the command id:{0}, Length:{1}", cmd.Head.CommandID, cmd.Head.MessageLength);
Unbind_Resp r = new Unbind_Resp();
cmd = Command.CreateCommand(r);
s.Send(cmd.GetBytes());
}
catch
{
}
}
}
catch
{
Console.WriteLine("hadn't receive message from server");
}
if (s.Poll(-1, SelectMode.SelectRead))
{
byte[] b = new byte[1024];
if (0 == s.Receive(b))
{
Console.WriteLine("server socket is disconnected!");
}
}
Console.Read();
}
finally
{
s.Shutdown(SocketShutdown.Both);
s.Close();
Console.Read();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -