[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:
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime;
using System.Net;
using Microsoft.VisualBasic;
using System.Net.Sockets;
using System.Collections;
namespace TestClient
{
public partial class TestClient : Form
{
ColumnHeader Header = new ColumnHeader();
ListViewItem Item = new ListViewItem();
ArrayList socketList = new ArrayList(5);
Socket newsock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
public YahKiller()
{
InitializeComponent();
}
private void Timer1_Tick(System.Object eventSender, System.EventArgs eventArgs)
{
short i = 0;
for (i = 0; i <= System.Convert.ToInt16(double.Parse(ServerList.Text) - 1); i++)
{
PacketsLabel.Text = System.Convert.ToString(double.Parse(PacketsLabel.Text) + 1);
if (newsock(i).Connected == newsock_ConnectEvent(eventSender, eventArgs)) /* this is the line of code i'm having some trouble with*/
{
string transTemp9 = LoginMod.ClientID[i];
string transTemp10 = (backup.Text);
newsock.SendFile(testfile.PM(ref transTemp9, ref transTemp10));
}
}
i = System.Convert.ToInt16(i + 1);
}
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'
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])"?
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)".
Re: [2.0] Need some Socket Help
Shazam! Sunburnt's answer was better though. :cry: ;)
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..
Re: [2.0] Need some Socket Help
But here is the VB6 to .NET upgrade Code:
VB Code:
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Dim i As Short
For i = 0 To CDbl(ClientList.Text) - 1
PacketsLabel.Text = CStr(CDbl(PacketsLabel.Text) + 1)
'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"'
If Socket(i).CtlState = MSWinsockLib.StateConstants.sckConnected Then
Socket(i).SendData(PM(ClientID(i), (Server.Text)))
End If
Next i
i = i + 1
End Sub