![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||