Results 1 to 6 of 6

Thread: [2.0] Need some Socket Help

  1. #1

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question [2.0] Need some Socket Help

    Ok this is what i have for Code than i'll explain the problem i'm having:
    VB Code:
    1. using System;
    2. using System.ComponentModel;
    3. using System.Data;
    4. using System.Drawing;
    5. using System.Text;
    6. using System.Windows.Forms;
    7. using System.IO;
    8. using System.Runtime;
    9. using System.Net;
    10. using Microsoft.VisualBasic;
    11. using System.Net.Sockets;
    12. using System.Collections;
    13. namespace TestClient
    14. {
    15.     public partial class TestClient : Form
    16.     {
    17.         ColumnHeader Header = new ColumnHeader();
    18.         ListViewItem Item = new ListViewItem();
    19.         ArrayList socketList = new ArrayList(5);
    20.         Socket newsock = new Socket(AddressFamily.InterNetwork,
    21.             SocketType.Stream, ProtocolType.Tcp);
    22.         public YahKiller()
    23.         {
    24.             InitializeComponent();
    25.  
    26.         }
    27. private void Timer1_Tick(System.Object eventSender, System.EventArgs eventArgs)
    28.         {
    29.             short i = 0;
    30.             for (i = 0; i <= System.Convert.ToInt16(double.Parse(ServerList.Text) - 1); i++)
    31.             {
    32.                 PacketsLabel.Text = System.Convert.ToString(double.Parse(PacketsLabel.Text) + 1);
    33.  
    34.                 if (newsock(i).Connected == newsock_ConnectEvent(eventSender, eventArgs)) /* this is the line of code i'm having some trouble with*/
    35.                 {
    36.                     string transTemp9 = LoginMod.ClientID[i];
    37.                     string transTemp10 = (backup.Text);
    38.                     newsock.SendFile(testfile.PM(ref transTemp9, ref transTemp10));
    39.                 }
    40.             }
    41.             i = System.Convert.ToInt16(i + 1);
    42.         }
    The issue i'm having is with : if (newsock(i).Connected == its the newsock that is giving me the problem,any ideas on the correction of this section of code will be appreciated...Thxs in Advance
    Here is the Error:
    Error 26 'TestClient.TestClient.newsock' is a 'field' but is used like a 'method'

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: [2.0] Need some Socket Help

    You've got some things mixed up:

    1) newsocket is a Socket, not an array of anything, so the parentheses are going to cause a problem.
    2) even if newsocket were an array, in c# the array indexer is the square brackets: array[n]
    3) It looks like you're trying to assign an event. If you're not, you can ignore this and #4 you assign events by using the += operator and an appropriate delegate:
    something.SomeEvent += new EventHandler(myEventHandler)
    4) Connected is not an event, it's a boolean property.


    Perhaps you meant simply "newsocket" or "((Socket)socketList[i])"?
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Need some Socket Help

    Firstly, 'newsock' is a Socket, so it has no indexer (equivalent to the default property in VB) so you cannot index it like that. Secondly, if you could index it you'd have to use square brackets, not parentheses. I'm guessing that you mean "socketList[i]", not "newsock(i)".
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Need some Socket Help

    Shazam! Sunburnt's answer was better though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question Re: [2.0] Need some Socket Help

    Is their a way for me to get VS 2005 to open VB6 like maybe installing the VB6 Runtime ,something like that...So i can translate the VB6 to .NET manually,the Convert Feature in VS 2005 just isnt that good..

    Tends to mess stuff up all the time..lol really dont want to Re Install Visual Basic 6 Program with VS 2005 installed on the same machine..
    Last edited by Rattlerr; Jul 13th, 2006 at 05:29 PM.

  6. #6

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Question Re: [2.0] Need some Socket Help

    But here is the VB6 to .NET upgrade Code:

    VB Code:
    1. Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
    2.         Dim i As Short
    3.         For i = 0 To CDbl(ClientList.Text) - 1
    4.             PacketsLabel.Text = CStr(CDbl(PacketsLabel.Text) + 1)
    5.             'UPGRADE_NOTE: State was upgraded to CtlState. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    6.             If Socket(i).CtlState = MSWinsockLib.StateConstants.sckConnected Then
    7.                 Socket(i).SendData(PM(ClientID(i), (Server.Text)))
    8.             End If
    9.         Next i
    10.         i = i + 1
    11.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width