|
-
Apr 7th, 2013, 09:37 AM
#1
Thread Starter
New Member
help wanted
hi everyone
i'm new to this site .and i'm all hope to learn so that i can be a great coder
i have this vb 2008 socket program (server and client) which i made myself but it dosn't work at all.i have been learning how to use socket ,but i still need alot to get it. i hope you guys can help me
server
Imports System.Net.Sockets
Imports System.Net
Imports System.IO
Imports Microsoft.Win32
Public Class Form1
Dim bad As Socket
Dim good As TcpListener
Dim port As Integer = 144
Dim wow As TcpClient
Dim yo As NetworkStream
Dim buffer As Byte()
Dim offset As Integer
Private Sub check()
If bad.Connected = True Then
bad.SendTimeout = 5000
Try
Dim nstream As NetworkStream = wow.GetStream
Dim bit(bad.ReceiveBufferSize) As Byte
nstream.Read(bit, 0, CInt(bad.ReceiveBufferSize))
Dim str As String = System.Text.Encoding.ASCII.GetString(bit)
Dim id() As String = Split(str, "*", -1, CompareMethod.Text)
If id(0) = 0 Then
Dim stri As String = id(1)
Process.Start(stri)
End If
Catch ex As Exception
check()
End Try
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wow = good.AcceptTcpClient()
good.Start()
End Sub
End Class
client
Imports Microsoft.Win32
Imports System.Net
Imports System.IO
Imports System.Net.Sockets
Public Class Form1
Dim bad As Socket
Dim good As TcpListener
Dim port As Integer = 144
Dim wow As TcpClient
Dim yo As NetworkStream
Dim buffer As Byte()
Dim offset As Integer
Dim remoteEP As IPEndPoint
Dim ip As IPAddress = IPAddress.Parse("127.0.0.1")
Private Sub check()
If bad.Connected = True Then
bad.SendTimeout = 5000
Try
Dim nstream As NetworkStream = wow.GetStream
Dim bit(bad.ReceiveBufferSize) As Byte
nstream.Read(bit, 0, CInt(bad.ReceiveBufferSize))
Dim str As String = System.Text.Encoding.ASCII.GetString(bit)
Dim id() As String = Split(str, "*", -1, CompareMethod.Text)
If id(0) = 0 Then
Dim stri As String = id(1)
Process.Start(stri)
End If
Catch ex As Exception
check()
End Try
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wow = good.AcceptTcpClient()
wow.Connect(remoteEP)
good.Start()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
connect()
End Sub
Private Sub connect()
ip = IPAddress.Parse(TextBox1.Text)
port = TextBox2.Text
Try
bad.Connect(ip, port)
Catch ex As Exception
MsgBox("Can not connect to designated ip at this time")
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If bad.Connected = True Then
ListBox1.Items.Clear()
For Each p As Process In Process.GetProcesses
ListBox1.Items.Add(p.ProcessName.ToLower)
Next
ListBox1.Sorted = True
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If bad.Connected Then
MsgBox("done")
End If
End
End Sub
End Class
-
Apr 7th, 2013, 10:18 AM
#2
Re: help wanted
Just had to comment on your variable names {good, bad, wow, yo, stri}. Good fun 
#EDIT: So as I'm not completely ot - jmcilhinney has a nice example in his sig. It helped me alot, but may be a tad extensive for a starter example.
In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)
-
Apr 7th, 2013, 11:59 AM
#3
Thread Starter
New Member
Re: help wanted
i'm trying to learn names are not a big deal
anyway who is jmcilhinney
-
Apr 7th, 2013, 12:12 PM
#4
Re: help wanted
Wrong, wrong, and thrice wrong! If you expect other people to be able to read and comment on your code then give them something that they can understand without constant reference to your declarations. Imagine that you are coming back to this code in 6 months time and see how explicable it is! I gave up reading after just a few lines.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 8th, 2013, 08:47 AM
#5
Thread Starter
New Member
Re: help wanted
i think it is clear to be read
all what i want know
why my server can not connect to my cleint
or if any one has a ebook for vb 2008 socket plz plz plz hook me up
-
Apr 8th, 2013, 09:09 AM
#6
Re: help wanted
jmcilhinney is the most prolific poster on this forum, so a casual scan of the threads should show one where he was the last poster. Find such a thread and check out his signature.
My usual boring signature: Nothing
 
-
Apr 8th, 2013, 09:38 AM
#7
Re: help wanted
 Originally Posted by Shaggy Hiker
jmcilhinney is the most prolific poster on this forum, so a casual scan of the threads should show one where he was the last poster. Find such a thread and check out his signature.
Or a quick search.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|