Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Problems sending data with System.Net.Sockets.Socket

Reply
 
Old 06-14-2007   #1 (permalink)
Coviti


 
 

Problems sending data with System.Net.Sockets.Socket

Hi all

For the last few days, I've been practicing my PS scripting by trying
to write a simple IRC client. So far I've only come up with this:

-- Begin Script --

#Initialize ASCIIEncoding object and create a Socket
$ASCIIEncoder = New-Object System.Text.ASCIIEncoding
$Socket = New-Object System.Net.Sockets.Socket
([System.Net.Sockets.AddressFamily]::InterNetwork,
[System.Net.Sockets.SocketType]::Stream,
[System.Net.Sockets.ProtocolType]::Tcp)

#Connect to IRC server
$Socket.Connect("irc.freenode.net",6667)

#Send user data
$Socket.Send($ASCIIEncoder.GetBytes("NICK UserName"))
$Socket.Send($ASCIIEncoder.GetBytes("USER UserName 8 * : UserName"))

#Declare variables needed for receiving server messages
[System.Byte[]]$Buffer = 0..255
[Int32]$CharacterCount

#Continue to receive and display messages until disconnected
while($true)
{
$CharacterCount = $Socket.Receive($Buffer)

#Disconnected: Clean up and exit loop
if($CharacterCount -le 0)
{
$Socket.Dispose
break;
}
Write-Host $($ASCIIEncoder.GetString($Buffer[0..[Int32]$
($CharacterCount-1)])) -noNewLine
}

-- End Script --

The script appears to work fine.. all methods return values indicating
success (including $Socket.Send(...)). However, after a few seconds,
the connection to the IRC server times out (behaving *exactly* as it
does in windows' telnet.exe if no NICK/USER information is sent). So
I'm assuming that somehow, even though the calls to $Socket.Send()
indicate success, the data is not getting through to the server.

Is there something that I'm doing wrong here?

NOTE: I have eliminated the possibility of network issues; I connect
to this server daily, and I can successfully connect through telnet
with the same settings.

Thanks,
Coviti


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Socket programming - how to identify accepted data? .NET General
System Sockets and Winsock in VB6 .NET General
facing data loss problem in socket programming while using IIS .NET General
Memory configurations in socket?2x256 socket 1/3 and 2x512 socket Vista hardware & devices
Connection problems using TCP/IP sockets Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46