//客户端连接服务器的方法 public void ClientConnectServer(string ip, int port, MyCallBack callBack) { clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); clientBuffer = new byte[1024]; clientCallBack = callBack; clientSocket.Connect(IPAddress.Parse(ip), port); //连接服务器 clientCallBack("连接服务器成功"); clientSocket.BeginReceive(clientBuffer, 0, clientBuffer.Length, SocketFlags.None, ClientReceive, clientSocket); }
private void Form1_Load(object sender, EventArgs e) { //初始化回调函数 m_call = new MyCallBack(OutputText); //注册回调函数回DLL Register_Callback(m_call); m_subthread = new SubThread(); //添加后台线程的消息处理实现函数, m_subthread.MessageSend += new SubThread.MessageEventHandler(this.Subthread_MessageSend); }
public void InitServer(MyCallBack callBack) { serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); serverBuffer = new byte[1024]; serverCallBack = callBack; IPEndPoint point = new IPEndPoint(IPAddress.Any, port); serverSocket.Bind(point); serverSocket.Listen(10); serverCallBack("服务器启动成功"); serverSocket.BeginAccept(ServerAccept, serverSocket); }
public event MyCallBack CallToMakeWhenDone = null; // call back delegate var public BreakfastItem(String BreakfastItemNameIn, int RandomwaitMax, ProgressBar progressBarin, MyCallBack callback) { this.RandomwaitMax = RandomwaitMax; BreakfastItemName = BreakfastItemNameIn; CallToMakeWhenDone = callback; myprogressBar = progressBarin; myprogressBar.MarqueeAnimationSpeed = 1000; myprogressBar.Maximum = RandomwaitMax; myprogressBar.Name = "progressBar Item"; myprogressBar.Size = new System.Drawing.Size(RandomwaitMax, 23); myprogressBar.Step = 10; myprogressBar.TabIndex = 2; StateCookingTimer(); }
public WinClient(Customer customer) { MyCallBack.SetDelegate(SetLabelMsg);
public static extern void Register_Callback([MarshalAs(UnmanagedType.FunctionPtr)] MyCallBack call);
private static extern void RegisterOutCallBack(MyCallBack c);
void MainFormLoad(object sender, EventArgs e) { if (m_i18ls == null) { Close(); } Mutex mutex; bool doesExist = true; try { mutex = Mutex.OpenExisting("MXDLOGIN"); } catch { doesExist = false; } if (doesExist) { MessageBox.Show(m_i18ls.get("msg/m51")); Close(); } else { mutex = new Mutex(true, "MXDLOGIN"); } try { // try to init dll DllInit(); } catch { // close if cannot MessageBox.Show(m_i18ls.get("msg/m1")); Close(); } // read conf file StringBuilder sb = new StringBuilder(100); GetPrivateProfileString("conf", "ip", "", sb, 100, "./conf.ini"); string ip = sb.ToString(); GetPrivateProfileString("conf", "loc", "", sb, 100, "./conf.ini"); string loc = sb.ToString(); GetPrivateProfileString("conf", "dev", "", sb, 100, "./conf.ini"); string dev = sb.ToString(); GetPrivateProfileString("conf", "path", "", sb, 100, "./conf.ini"); m_strFilepath = sb.ToString(); GetPrivateProfileString("conf", "port", "8484", sb, 100, "./conf.ini"); m_portBox.Text = sb.ToString(); GetPrivateProfileString("conf", "noport", "", sb, 100, "./conf.ini"); m_extendPage.m_NoPortBox.Text = sb.ToString(); int select = 0; // read adapters ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { string[] ips = (string [])(mo["IPAddress"]); if (ips != null) { if (!m_AdaptorcomboBox.Items.Contains(ips[0])) { m_AdaptorcomboBox.Items.Add(ips[0]); } } } m_AdaptorcomboBox.Items.Add("\\DEVICE\\NDISWANIP"); for (int i = 0; i < m_AdaptorcomboBox.Items.Count; i++) { if (((string)m_AdaptorcomboBox.Items[i]).Equals(dev)) { select = i; } } m_AdaptorcomboBox.SelectedIndex = select; m_ipBox.Text = ip; m_callInC = new MyCallBack(InCallBack); m_callOutC = new MyCallBack(OutCallBack); // opened m_bOpened = true; }