نمایش نتایج 1 تا 6 از 6

نام تاپیک: Sockets !

  1. #1
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    Iran - Tehran
    پست
    799

    Sockets !

    سلام.
    فرض کنید تو یه برنامه Client\Server بخش server برنامه باید امکان جواب دادن به چند تا client رو داشته باشه.من برای ارتباط از winsock استفاده میکنم.
    برای رویداد OnRequest همیشه کد زیر رو مینوشتم (در حالتی که برنامه فقط یه client داره) :

    Private sub Winsock_OnRequest(RequestID as long)
    if winsock.state <> sckclosed then winsock.close
    winsock.Accept(requestID)
    End sub


    ولی برای نیازی که الان دارم این روش جواب نمیده و ارتباط قبلی رو میبنده !؟
    :cry:

  2. #2
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    Iran - Tehran
    پست
    799
    :cry: بابا یه راهمنایی ، چیزی !

  3. #3
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    ایران - تهران
    پست
    2,342
    Accepting More than One Connection Request (ref. MSDN)
    However, it is possible to accept several connection requests using the same control by creating a control array. In that case, you do not need to close the connection, but simply create a new instance of the control (by setting its Index property), and invoking the Accept method on the new instance.

    The code below assumes there is a Winsock control on a form named sckServer, and that its Index property has been set to 0; thus the control is part of a control array. In the Declarations section, a module-level variable intMax is declared. In the form's Load event, intMax is set to 0, and the LocalPort property for the first control in the array is set to 1001. Then the Listen method is invoked on the control, making it the "listening control. As each connection request arrives, the code tests to see if the Index is 0 (the value of the "listening" control). If so, the listening control increments intMax, and uses that number to create a new control instance. The new control instance is then used to accept the connection request.

    Private intMax As Long

    Private Sub Form_Load()
    intMax = 0
    sckServer(0).LocalPort = 1001
    sckServer(0).Listen
    End Sub

    Private Sub sckServer_ConnectionRequest _
    (Index As Integer, ByVal requestID As Long)
    If Index = 0 Then
    intMax = intMax + 1
    Load sckServer(intMax)
    sckServer(intMax).LocalPort = 0
    sckServer(intMax).Accept requestID
    Load txtData(intMax)
    End If
    End Sub


    در ضمن من رخداد OnRequest ندیدم بجای آن ConnectionRequest وجود دارد. نکته ی بالا هم خوب است !! :wink:

  4. #4
    در وبلاگ http://vblog.persianblog.com مقاله ای درباره استفاده از سوکت در جند بخش نوشته شده است که می توانید جواب سوالتان را در آن بیابید

  5. #5
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    Iran - Tehran
    پست
    799
    سلام.
    خیلی ممنون وحید جان و Voldemort عزیز :wink:
    در همین مورد یه مشکل دیگه هم داشتم ... فرض کنید که بخوایم یه برنامه برای monitor کردن اطلاعات ارسالی و دریافتی بنویسیم و البته روی یه پ.رت که از قبل یه برنامه دیگه اون رو باز کرده...
    مثلا بخوایم اطلاعاتی رو که یه messenger میفرسته (به سرورش) و میگیره رو log کنیم.
    اگه از winsock استفاده کنیم خطای Address in use رو میده .
    برای حل این باید چی کار کرد ؟
    ممنون.

  6. #6
    مرسی آقا عالی بود

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •