小编omi*_*omi的帖子

套接字编程 - 客户端服务器原理

我甚至不好意思问这个问题,但经过谷歌的一次精疲力竭的搜索(开始有MSDN ......)后,我决定发布它:

刚刚开始学习客户端 - 服务器编程(使用C#),并尝试使用tcpClient编写我的第一个代码.我正在写服务器端和客户端.这是我的问题:不断,客户端将一个String发送到服务器,然后服务器将一个String发送回客户端,依此类推.服务器不能连续发送2个字符串吗?他必须等待客户的回应?这是客户端服务器的原理吗?

再一次,抱歉这个糟糕的问题.谢谢...

<>我会尝试发布一些代码(很长的代码......).我试图削减redandent部分,所以希望代码有任何意义...(我用//*********标记主要的problam)

public class MServer2
{
Dictionary<String, String> nameAndPass = new Dictionary<String, String>();
Dictionary<String, List<String> > nameAndMail = new Dictionary<String, List<String>>();

public static void Main()
{
    new MServer2();
}

public MServer2()
{
    TcpListener server = new TcpListener(8500);
    try
    {
        server.Start();
        Console.WriteLine("started " + server);
        while (true)
        {
            TcpClient client = server.AcceptTcpClient();
            Console.WriteLine("connection accepted " + client);
            new Server1(client, nameAndPass, nameAndMail);
        }
    }
    catch (Exception e)
    {
        Console.WriteLine("exception" + e);
    }
    finally
    {
        server.Stop();
    } …
Run Code Online (Sandbox Code Playgroud)

c# tcpclient

4
推荐指数
1
解决办法
1170
查看次数

使用TextBox进行用户文本输入处理

我有这个控制权:

在此输入图像描述

我正在尝试创建一种验证,每当用户向TextBox输入文本时,"添加"按钮将被启用,当文本为""(空)时,"添加"按钮被禁用.我不想使用验证器.

这是代码:

protected void addNewCategoryTB_TextChanged(object sender, EventArgs e)
    {
        if (addNewCategoryTB.Text != "")
            addNewCategoryBtn.Enabled = true;
        else
            addNewCategoryBtn.Enabled = false;
    }
Run Code Online (Sandbox Code Playgroud)

问题是,当用户输入文本时,"添加"按钮不会从禁用更改为启用(反之亦然)...

有任何想法吗?

c# asp.net textbox

1
推荐指数
1
解决办法
537
查看次数

重载operator []以获取模板类-c ++

刚写了一个模板数组类的代码(我知道它还没有完成),并试图记住如何重载运算符(同时没有特殊的困难......).

无论如何,在思考如何实现时operator[]我想知道如果索引超出数组边界会发生什么...我很确定我不可能返回NULL(因为返回类型),对?如果是这样,如果索引超出边界,我应该返回什么?

这里是代码,大部分内容对我的问题都是多余的,但它可能会帮助谷歌运营商超载的任何人,所以我发布了完整的代码......

#ifndef __MYARRAY_H
#define __MYARRAY_H

#include <iostream>
using namespace std;

template <class T>
class MyArray
{
    int phisicalSize, logicalSize;
    char printDelimiter;
    T* arr;

public: 
    MyArray(int size=10, char printDelimiter=' ');
    MyArray(const MyArray& other);
    ~MyArray() {delete []arr;}

    const MyArray& operator=(const MyArray& other);
    const MyArray& operator+=(const T& newVal);

    T& operator[](int index);

    friend ostream& operator<<(ostream& os, const MyArray& ma)
    {
        for(int i=0; i<ma.logicalSize; i++)
            os << ma.arr[i] << ma.printDelimiter;
        return os;
    }
};

template <class T>
T& MyArray<T>::operator[]( int index …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading

0
推荐指数
1
解决办法
734
查看次数

标签 统计

c# ×2

asp.net ×1

c++ ×1

operator-overloading ×1

tcpclient ×1

textbox ×1