B
bottom
Unregistered / Unconfirmed
GUEST, unregistred user!
一个TCP的SERVER的程序遇到的问题<br><br>不过运行时出先RUNTIM的错误,大家帮忙看看如何修改啊?<br><br>program Project1;<br>{$APPTYPE CONSOLE} <br><br>uses Windows,winsock; <br><br>var<br> TempWSAData: TWSAData;<br> s: TSocket;<br> addr: TSockAddr;<br> RemoteAddr: PSockAddr;<br> SinSize: integer; <br><br>const<br>CRLF=#13#10;<br>UDPPORT = 6767; //设定UDP端口号 <br><br>BEGIN<br> if WSAStartup($101, TempWSAData)=1 then<br> Writeln('StartUp Error!'); <br><br> s := Socket(AF_INET, sock_stream, 0);<br> if (s = INVALID_SOCKET) then //Socket创建失败<br> begin<br> Writeln('Socket创建失败');<br> CloseSocket(s);<br>// exit;<br> end;<br> //发送方SockAddr绑定<br> addr.sin_family := AF_INET;<br> addr.sin_addr.S_addr := INADDR_ANY;<br> addr.sin_port := htons(UDPPORT);<br> if Bind(s, addr, sizeof(addr)) <> 0 then<br> begin<br> Writeln('bind fail');<br> end;<br> //监听<br> write('listen = ');<br> listen(s,5);<br> Writeln(Listen(s,5));<br> write('accept = ');<br> New(RemoteAddr);<br> SinSize := SizeOf(RemoteAddr);<br> accept(s, RemoteAddr, PInteger(SinSize));<br> //write(accept(s, RemoteAddr, PInteger(SinSize)));<br>END. <br><br><br> <br>