A simple server program in c++
I currently have the following server wrote in vb6:
Option Explicit
Dim sServerMsg As String
Private Sub Form_Load()
'Address must be input as a string
Dim Address As String
'Set the address equal to the web address of the pickle line camera
Address = "http://pl7cam2/operator/image_test.shtml?camNo=1&squarepixel=0&resolution=4CIF&compression=35&color=yes&rotation=0&overlayim age=0&overlaypos=0x0&date=1&clock=1&text=1&textstring=%237%20Pickle%20Exit%20Camera&textcolor=white& textbackgroundcolor=black&textpos=top&duration=NaN&fps=0kkkkkkkkkkkkkkk"
'tells the browser window to display whatever is on the web page of the address
WebBrowser1.Navigate Address
'The port number is arbitrary.
' it's best to use a fairly high number
' because the low numbers are used for
' standard services: 21 for FTP, 23 for telnet,
' 80 for HTTP etc...
Winsock1(0).LocalPort = 10119
'start listening for a connection
Winsock1(0).Listen
'Define the message and show the connection in the list box
sServerMsg = "Listening to port: "
List1.AddItem (sServerMsg)
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
'the winsock control has to be in a closed state
' before it can do anything else. (like accept a connection)
Winsock1(Index).Close
'Let the winsock close
DoEvents
'accept the connection request
Winsock1(Index).Accept requestID
'Define the message and display it in the list box
sServerMsg = "Serving client!"
List1.AddItem (sServerMsg)
End Sub
Private Sub Winsock1_Close(Index As Integer)
'When the other end has closed the connection,
' close server end too
Winsock1(Index).Close
'to continue listening for another connection
Winsock1(Index).Listen
'show the connection in the list box
sServerMsg = "Listening to port: "
List1.AddItem (sServerMsg)
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strTemp As String
'Dim strTemp2 As String
Dim a As Integer
'This event fires when the process on the other end of the connection(i.e the client)
'sends data
'retreive data from socket
Winsock1(Index).GetData strTemp
'Winsock1(Index).GetData strTemp2
'The following code separates each part of the string based on the comma
'that is present in the incoming string and parses it out into its
'respective textbox
a = InStr(strTemp, ",")
txtcoilid.Text = Left(strTemp, a - 1)
'after the first parse you must refine the string as everthing after the comma and
'repeat the process throughout the entire string
strTemp = Mid(strTemp, a + 1)
a = InStr(strTemp, ",")
txtwidth.Text = Left(strTemp, a - 1)
strTemp = Mid(strTemp, a + 1)
a = InStr(strTemp, ",")
txtlinespeed.Text = Left(strTemp, a - 1)
strTemp = Mid(strTemp, a + 1)
a = InStr(strTemp, ",")
txtexitcoillength.Text = Left(strTemp, a - 1)
End Sub
I need to code this server on a linux machine using c++ or any other valid linux language. I have no experience in c or c++ coding at all. I was wondering if I could get some insight on some possible translation for this code or some similar source code that may help me.
|